Skip to content

Commit 20e73f3

Browse files
committed
Implement std::borrow::Borrow for Atom
I want to be able to use connect() on Atoms, which requires Borrow be implemented
1 parent baab352 commit 20e73f3

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

src/atom/mod.rs

+16
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
use phf::OrderedSet;
1313

14+
use std::borrow::Borrow;
1415
use std::fmt;
1516
use std::mem;
1617
use std::ops;
@@ -303,6 +304,13 @@ impl Ord for Atom {
303304
}
304305
}
305306

307+
impl Borrow<str> for Atom {
308+
fn borrow(&self) -> &str {
309+
&self
310+
}
311+
}
312+
313+
306314
#[cfg(test)]
307315
mod bench;
308316

@@ -522,4 +530,12 @@ mod tests {
522530
let atom = Atom::from_slice("foobar");
523531
let _: &str = &atom;
524532
}
533+
534+
#[test]
535+
fn ensure_borrow() {
536+
// Ensure std::borrow::Borrow is implemented
537+
let atoms = vec![Atom::from_slice("foo"), Atom::from_slice("bar")];
538+
let joined_atoms = atoms.connect(" ");
539+
assert_eq!(joined_atoms, "foo bar");
540+
}
525541
}

0 commit comments

Comments
 (0)