-
Notifications
You must be signed in to change notification settings - Fork 13
Open
Description
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.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels