Relative Content

Tag Archive for rust

How can I write an efficient builder in Rust?

Lets say I want to write a type that builds a fairly large string (lets say of html) then returns it without copying or cloning the string. Is there a way that I can implement an unwrap function that will prevent further access to the builder.

How can I write an efficient builder in Rust?

Lets say I want to write a type that builds a fairly large string (lets say of html) then returns it without copying or cloning the string. Is there a way that I can implement an unwrap function that will prevent further access to the builder.

Casting a number from one type to another: the trait bound `usize: From` is not satisfied

I have a function that gets the dimensions of an image, and in different scenarios, I would it to be cast from a u32 to another number type suchas usize, i32, etc. However, when I try to do the following in get_dimensions it doesn’t work. Is something like this possible? I looked at How do I convert between numeric types safely and idiomatically? but in that example it uses an explicit type such as i32::from(...) whereas I would hopefully like to use a dynamic type.