Skip to content

Commit 14eb4ec

Browse files
authored
Adds AsRef<[Element]> for Sequence, List, and SExp (#841)
1 parent c78292e commit 14eb4ec

File tree

3 files changed

+18
-0
lines changed

3 files changed

+18
-0
lines changed

src/element/sequence.rs

+6
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,12 @@ impl AsRef<Sequence> for Sequence {
131131
}
132132
}
133133

134+
impl AsRef<[Element]> for Sequence {
135+
fn as_ref(&self) -> &[Element] {
136+
self.elements.as_slice()
137+
}
138+
}
139+
134140
// This is more efficient than Sequence::new(), which will iterate over and convert each value to
135141
// an Element for better ergonomics.
136142
impl From<Vec<Element>> for Sequence {

src/types/list.rs

+6
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,12 @@ impl AsRef<Sequence> for List {
5252
}
5353
}
5454

55+
impl AsRef<[Element]> for List {
56+
fn as_ref(&self) -> &[Element] {
57+
self.0.as_ref()
58+
}
59+
}
60+
5561
// Allows `for element in &list {...}` syntax
5662
impl<'a> IntoIterator for &'a List {
5763
type Item = &'a Element;

src/types/sexp.rs

+6
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,12 @@ impl AsRef<Sequence> for SExp {
5252
}
5353
}
5454

55+
impl AsRef<[Element]> for SExp {
56+
fn as_ref(&self) -> &[Element] {
57+
self.0.as_ref()
58+
}
59+
}
60+
5561
// Allows `for element in &sexp {...}` syntax
5662
impl<'a> IntoIterator for &'a SExp {
5763
type Item = &'a Element;

0 commit comments

Comments
 (0)