From de643163f54dfe1300ab21fb6f22f345dbc2830c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20S=C3=A1=20de=20Mello?= Date: Mon, 14 Oct 2024 23:52:49 +0100 Subject: [PATCH] update changelog and add a couple tests --- CHANGELOG.md | 7 +++++++ src/pointer.rs | 16 +++++++++++++++- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5306efd..d06d18f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,13 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [Unreleased] + +### Added + +- Adds unsafe associated methods `Pointer::new_unchecked` and `PointerBuf::new_unchecked` for + external zero-cost construction. + ## [0.6.2] 2024-09-30 ### Added diff --git a/src/pointer.rs b/src/pointer.rs index 67840b1..18f3e67 100644 --- a/src/pointer.rs +++ b/src/pointer.rs @@ -51,7 +51,7 @@ impl core::fmt::Display for Pointer { impl Pointer { /// Create a `Pointer` from a string that is known to be correctly encoded. /// - /// This is a zero-copy constructor. + /// This is a cost-free conversion. /// /// ## Safety /// The provided string must adhere to RFC 6901. @@ -1302,6 +1302,20 @@ mod tests { let _ = Pointer::from_static("foo/bar"); } + #[test] + fn root_is_alias_of_new_pathbuf() { + assert_eq!(PointerBuf::root(), PointerBuf::new()); + } + + #[test] + fn from_unchecked_pathbuf() { + let s = "/foo/bar/0"; + assert_eq!( + unsafe { PointerBuf::new_unchecked(String::from(s)) }, + PointerBuf::parse(s).unwrap() + ); + } + #[test] fn strip_suffix() { let p = Pointer::from_static("/example/pointer/to/some/value");