refactor(core/rust/ui): use AsRef instead of Deref

[no changelog]
pull/2678/head
Martin Milata 2 years ago
parent 387af03842
commit 11ffee0b45

@ -1,5 +1,3 @@
use core::ops::Deref;
use crate::ui::{
component::{Component, Event, EventCtx, Never},
display::Font,
@ -15,7 +13,7 @@ pub struct Label<T> {
impl<T> Label<T>
where
T: Deref<Target = str>,
T: AsRef<str>,
{
pub fn new(text: T, align: Alignment, style: TextStyle) -> Self {
Self {
@ -54,13 +52,13 @@ where
pub fn max_size(&self) -> Offset {
let font = self.font();
Offset::new(font.text_width(&self.text), font.text_max_height())
Offset::new(font.text_width(self.text.as_ref()), font.text_max_height())
}
}
impl<T> Component for Label<T>
where
T: Deref<Target = str>,
T: AsRef<str>,
{
type Msg = Never;
@ -75,7 +73,7 @@ where
}
fn paint(&mut self) {
self.layout.render_text(&self.text);
self.layout.render_text(self.text.as_ref());
}
fn bounds(&self, sink: &mut dyn FnMut(Rect)) {
@ -86,9 +84,9 @@ where
#[cfg(feature = "ui_debug")]
impl<T> crate::trace::Trace for Label<T>
where
T: Deref<Target = str>,
T: AsRef<str>,
{
fn trace(&self, t: &mut dyn crate::trace::Tracer) {
t.string(&self.text)
t.string(self.text.as_ref())
}
}

@ -1,5 +1,3 @@
use core::ops::Deref;
use crate::ui::{
component::{Child, Component, Event, EventCtx, Image, Label},
display,
@ -39,7 +37,7 @@ pub struct FidoConfirm<F: Fn(usize) -> T, T, U> {
impl<F, T, U> FidoConfirm<F, T, U>
where
F: Fn(usize) -> T,
T: Deref<Target = str> + From<&'static str>,
T: AsRef<str> + From<&'static str>,
U: Component<Msg = CancelConfirmMsg>,
{
pub fn new(
@ -49,7 +47,7 @@ where
icon_name: Option<T>,
controls: U,
) -> Self {
let icon_data = get_fido_icon_data(icon_name.as_deref());
let icon_data = get_fido_icon_data(icon_name.as_ref());
// Preparing scrollbar and setting its page-count.
let mut scrollbar = ScrollBar::horizontal();
@ -104,7 +102,7 @@ where
impl<F, T, U> Component for FidoConfirm<F, T, U>
where
F: Fn(usize) -> T,
T: Deref<Target = str> + From<&'static str>,
T: AsRef<str> + From<&'static str>,
U: Component<Msg = CancelConfirmMsg>,
{
type Msg = FidoMsg;
@ -179,7 +177,9 @@ where
// Account name is optional.
// Showing it only if it differs from app name.
// (Dummy requests usually have some text as both app_name and account_name.)
if !current_account.is_empty() && current_account.deref() != self.app_name.text().deref() {
if !current_account.as_ref().is_empty()
&& current_account.as_ref() != self.app_name.text().as_ref()
{
self.account_name.set_text(current_account);
self.account_name.paint();
}

@ -1,5 +1,3 @@
use core::ops::Deref;
use crate::ui::{
component::{maybe::paint_overlapping, Child, Component, Event, EventCtx, Label, Maybe},
geometry::{Alignment, Grid, Offset, Rect},
@ -29,7 +27,7 @@ pub struct MnemonicKeyboard<T, U> {
impl<T, U> MnemonicKeyboard<T, U>
where
T: MnemonicInput,
U: Deref<Target = str>,
U: AsRef<str>,
{
pub fn new(input: T, prompt: U) -> Self {
Self {
@ -90,7 +88,7 @@ where
impl<T, U> Component for MnemonicKeyboard<T, U>
where
T: MnemonicInput,
U: Deref<Target = str>,
U: AsRef<str>,
{
type Msg = MnemonicKeyboardMsg;

@ -1,4 +1,4 @@
use core::{mem, ops::Deref};
use core::mem;
use heapless::String;
use crate::{
@ -56,7 +56,7 @@ pub struct PinKeyboard<T> {
impl<T> PinKeyboard<T>
where
T: Deref<Target = str>,
T: AsRef<str>,
{
// Label position fine-tuning.
const MAJOR_OFF: Offset = Offset::y(-2);
@ -150,7 +150,7 @@ where
impl<T> Component for PinKeyboard<T>
where
T: Deref<Target = str>,
T: AsRef<str>,
{
type Msg = PinKeyboardMsg;
@ -464,7 +464,7 @@ impl Component for PinDots {
#[cfg(feature = "ui_debug")]
impl<T> crate::trace::Trace for PinKeyboard<T>
where
T: Deref<Target = str>,
T: AsRef<str>,
{
fn trace(&self, t: &mut dyn crate::trace::Tracer) {
t.open("PinKeyboard");

@ -1,4 +1,4 @@
use core::{cmp::Ordering, convert::TryInto, ops::Deref};
use core::{cmp::Ordering, convert::TryInto};
use crate::{
error::Error,
@ -95,7 +95,7 @@ impl TryFrom<SelectWordCountMsg> for Obj {
impl<F, T, U> ComponentMsgObj for FidoConfirm<F, T, U>
where
F: Fn(usize) -> T,
T: Deref<Target = str> + From<&'static str>,
T: ParagraphStrType + From<&'static str>,
U: Component<Msg = CancelConfirmMsg>,
{
fn msg_try_into_obj(&self, msg: Self::Msg) -> Result<Obj, Error> {
@ -149,7 +149,7 @@ where
impl<T> ComponentMsgObj for PinKeyboard<T>
where
T: Deref<Target = str>,
T: AsRef<str>,
{
fn msg_try_into_obj(&self, msg: Self::Msg) -> Result<Obj, Error> {
match msg {
@ -171,7 +171,7 @@ impl ComponentMsgObj for PassphraseKeyboard {
impl<T, U> ComponentMsgObj for MnemonicKeyboard<T, U>
where
T: MnemonicInput,
U: Deref<Target = str>,
U: AsRef<str>,
{
fn msg_try_into_obj(&self, msg: Self::Msg) -> Result<Obj, Error> {
match msg {

Loading…
Cancel
Save