Skip to content

SharedString cannot be converted into `std::borrow::Cow<'static, str>' #581

Open
@vstojkovic-mongodb

Description

@vstojkovic-mongodb

Although the conversion is implemented, the compiler won't let me use it because str is not Sized.

For example, the following code:

struct MetricMetadata {
    description: SharedString,
    unit: Option<Unit>,
}

impl MetricMetadata {
    fn description(&self) -> std::borrow::Cow<'static, str> {
        self.description.into()
    }
}

refuses to compile with the following error:

error[E0277]: the size for values of type `str` cannot be known at compilation time
  --> src/metadata.rs:38:26
   |
38 |         self.description.into()
   |                          ^^^^ doesn't have a size known at compile-time
   |
   = help: the trait `std::marker::Sized` is not implemented for `str`
   = note: required for `std::borrow::Cow<'_, str>` to implement `std::convert::From<metrics::cow::Cow<'_, str>>`
   = note: required for `metrics::cow::Cow<'_, str>` to implement `std::convert::Into<std::borrow::Cow<'_, str>>`

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-coreComponent: core functionality such as traits, etc.E-simpleEffort: simple.T-bugType: bug.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions