Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: into_v1 #121

Merged
merged 2 commits into from
Aug 8, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions src/cid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,19 @@ impl<const S: usize> Cid<S> {
}
}

/// Convert a CIDv0 to a CIDv1
Copy link
Member

Choose a reason for hiding this comment

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

Nitpick (change will be approved and merge even without changing it): Perhaps adding information that if it is already a CIDv1, that it will be unchanged.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I literally wrote it out, thought it was a bit verbose compared to the others and dropped it. Also test incoming :)

pub fn into_v1(self) -> Result<Self> {
match self.version {
Version::V0 => {
if self.codec != DAG_PB {
return Err(Error::InvalidCidV0Codec);
}
Ok(Self::new_v1(self.codec, self.hash))
}
Version::V1 => Ok(self),
}
}

/// Returns the cid version.
pub const fn version(&self) -> Version {
self.version
Expand Down