You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently Measurement::new() takes an &[u8] argument. Since this type is just a wrapper around Vec<u8> it would be better to take an owned Vec directly.
Because the type needs an owned copy of the data, when passed a reference it must immediately clone it. This is fine if the caller also needs a copy. If it's constructed just to pass in and is not needed otherwise, the clone is unnecessary extra work. This can be avoided by taking the vector by value. If the caller needs to retain a copy, it can explicitly clone.
let data:&[u8] = get_intput();let m = Measurement::new(data.clone());
This makes it clear in the API contract that an allocation is happening, and avoiding it is up to the caller.
The impl From<&str> would then make its own clone call, as an immediate example.
The text was updated successfully, but these errors were encountered:
Currently
Measurement::new()
takes an&[u8]
argument. Since this type is just a wrapper aroundVec<u8>
it would be better to take an ownedVec
directly.Because the type needs an owned copy of the data, when passed a reference it must immediately clone it. This is fine if the caller also needs a copy. If it's constructed just to pass in and is not needed otherwise, the clone is unnecessary extra work. This can be avoided by taking the vector by value. If the caller needs to retain a copy, it can explicitly clone.
This makes it clear in the API contract that an allocation is happening, and avoiding it is up to the caller.
The
impl From<&str>
would then make its ownclone
call, as an immediate example.The text was updated successfully, but these errors were encountered: