Skip to content

Measurement constructors should take owned data #16

@rillian

Description

@rillian

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions