Skip to content

Conversation

ghost
Copy link

@ghost ghost commented Feb 20, 2021

New public APIs

#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum AttrValue<'string> {
    True,
    False,
    String(&'string str),
    Bytes(&'string [u8]),
    Unspecified,
}

impl<'string> AttrValue<'string> {
    pub fn from_string(_: Option<&'string str>) -> Self;
    pub fn from_bytes(_: Option<&'string [u8]>) -> Self;
}

Summary

  • Adds some new public APIs as described above.
  • States that the return types of Repository::get_attr and Repository::get_attr_bytes will probably be changed in the next major version in their documentations.

Wrapping the return value of Repository::get_attr(_bytes) in a new type is probably better, but that's a breaking change, so it's probably not desirable unless it's ready to bump to 0.14.

Resolves #670.

src/lib.rs Outdated

/// Converts [`AttrValueBytes`] to [`AttrValue`]. If the attribute is [set to a string](`AttrValueBytes::String`),
/// this implementation will use [`str::from_utf8`] to perform the conversion.
impl<'string> TryFrom<AttrValueBytes<'string>> for AttrValue<'string> {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of having two enums, could there perhaps be one enum with a string/bytes variant where the bytes are guaranteed to always be invalid utf-8?

Copy link
Author

@ghost ghost Feb 23, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

where the bytes are guaranteed to always be invalid utf-8?

Does that mean AttrValue::new() will always perform UTF-8 validation? Could I add another new that skips UTF-8 validation and always return bytes if the value is string?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems reasonable to me!

@alexcrichton alexcrichton merged commit 65c0dcc into rust-lang:master Feb 24, 2021
@alexcrichton
Copy link
Member

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

No git_attr_value() binding
2 participants