yewstack / implicit-clone

Immutable types and ImplicitClone trait similar to Copy
19 stars 10 forks source link

Add macro iformat!() which is exactly the same as format!() #15

Closed cecton closed 1 year ago

WorldSEnder commented 1 year ago

Not sure if I like this, since it requires that the correct IString is in context (either sync or unsync) and one could just as easily write format!("{}", 42).into(), could one not?

cecton commented 1 year ago

one could just as easily write format!("{}", 42).into(), could one not?

Sometimes yes... but in yew you need to specify the type because it cannot infer it when used directly in props. So, often you need to write AttrValue::from(format!(...)).

let stuff = format!("").into()
html! {
    <MyComponent {stuff} />      <--- often fails with "type annotations needed"
}

Not sure if I like this, since it requires that the correct IString is in context

It was actually done on purpose that IString must be in scope. It's a bit like String is always in scope. I did exactly because there are 2 distinct implementations.

Also it's not in the prelude of the crate. Not super invasive nor high maintenance

cecton commented 1 year ago

I'm adding iarray![] which I also find is missing ^_^

cecton commented 1 year ago

I think I'm making the matter worst haha xD

It's okay I don't absolutely want macros. It's okay to disagree

ranile commented 1 year ago

This will invoke ToString, which may end up cloning the data inside, and thus violate the "reference count increase or 'static" API. I'm not sure how I feel about this

cecton commented 1 year ago

This will invoke ToString, which may end up cloning the data inside, and thus violate the "reference count increase or 'static" API. I'm not sure how I feel about this

ahh... you think? ... :thinking: only iformat!() you mean? Ah yes format!() itself could...

idk... I don't mind closing it for now. Though I guess people would expect that iformat, just like format, would allocate.

I will re-open it in the future if I feel this feature is really worthy.