Skip to content

Commit

Permalink
Adds AsRef<[Element]> for Sequence, List, and SExp (#841)
Browse files Browse the repository at this point in the history
  • Loading branch information
popematt authored Oct 8, 2024
1 parent c78292e commit 14eb4ec
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/element/sequence.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,12 @@ impl AsRef<Sequence> for Sequence {
}
}

impl AsRef<[Element]> for Sequence {
fn as_ref(&self) -> &[Element] {
self.elements.as_slice()
}
}

// This is more efficient than Sequence::new(), which will iterate over and convert each value to
// an Element for better ergonomics.
impl From<Vec<Element>> for Sequence {
Expand Down
6 changes: 6 additions & 0 deletions src/types/list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,12 @@ impl AsRef<Sequence> for List {
}
}

impl AsRef<[Element]> for List {
fn as_ref(&self) -> &[Element] {
self.0.as_ref()
}
}

// Allows `for element in &list {...}` syntax
impl<'a> IntoIterator for &'a List {
type Item = &'a Element;
Expand Down
6 changes: 6 additions & 0 deletions src/types/sexp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,12 @@ impl AsRef<Sequence> for SExp {
}
}

impl AsRef<[Element]> for SExp {
fn as_ref(&self) -> &[Element] {
self.0.as_ref()
}
}

// Allows `for element in &sexp {...}` syntax
impl<'a> IntoIterator for &'a SExp {
type Item = &'a Element;
Expand Down

0 comments on commit 14eb4ec

Please sign in to comment.