Skip to content

Commit e09fa66

Browse files
committed
Add Patricia::insert_str() doc
1 parent af9703a commit e09fa66

File tree

1 file changed

+27
-1
lines changed

1 file changed

+27
-1
lines changed

src/map.rs

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,33 @@ impl<V> PatriciaMap<V> {
142142
self.tree.insert(key, value)
143143
}
144144

145-
#[allow(missing_docs)]
145+
/// As with [`PatriciaMap::insert()`] except for that this method regards UTF-8 character boundaries of the input key.
146+
147+
/// # Examples
148+
///
149+
/// ```
150+
/// use patricia_tree::PatriciaMap;
151+
///
152+
/// // Insert keys as opaque byte strings.
153+
/// //
154+
/// // Node labels can be arbitrary byte strings.
155+
/// let mut map = PatriciaMap::new();
156+
/// map.insert("🌏🗻", ()); // [240, 159, 140, 143, 240, 159, 151, 187]
157+
/// map.insert("🌏🍔", ()); // [240, 159, 140, 143, 240, 159, 141, 148]
158+
///
159+
/// let first_label = map.as_ref().child().unwrap().label();
160+
/// assert_eq!(first_label, [240, 159, 140, 143, 240, 159]);
161+
///
162+
/// // Insert keys as UTF-8 strings.
163+
/// //
164+
/// // Node labels are guaranteed to be UTF-8 byte strings.
165+
/// let mut map = PatriciaMap::new();
166+
/// map.insert_str("🌏🗻", ());
167+
/// map.insert_str("🌏🍔", ());
168+
///
169+
/// let first_label = map.as_ref().child().unwrap().label();
170+
/// assert_eq!(first_label, "🌏".as_bytes());
171+
/// ```
146172
pub fn insert_str(&mut self, key: &str, value: V) -> Option<V> {
147173
self.tree.insert_str(key, value)
148174
}

0 commit comments

Comments
 (0)