Skip to content

Commit 03f3e94

Browse files
billfCopilot
andauthored
Apply suggestions from code review
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent 44601fe commit 03f3e94

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

src/semver.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,23 @@ impl<T> VersionMap<T> {
106106
}
107107

108108
/// Gets a value by version or returns the latest version if no specific version is provided.
109+
///
110+
/// # Examples
111+
///
112+
/// ```rust
113+
/// use semver::Version;
114+
/// # use wac_trampoline::semver::VersionMap;
115+
///
116+
/// let mut map = VersionMap::new();
117+
/// map.insert(Version::new(1, 0, 0), "v1.0.0");
118+
/// map.insert(Version::new(1, 2, 0), "v1.2.0");
119+
///
120+
/// // Get a specific version
121+
/// assert_eq!(map.get_or_latest(Some(&Version::new(1, 0, 0))), Some(&"v1.0.0"));
122+
///
123+
/// // Get the latest version
124+
/// assert_eq!(map.get_or_latest(None), Some(&"v1.2.0"));
125+
/// ```
109126
pub fn get_or_latest(&self, version: Option<&Version>) -> Option<&T> {
110127
match version {
111128
Some(v) => self.get(v),

0 commit comments

Comments
 (0)