Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds AsRef<[Element]> for Sequence, List, and SExp #841

Merged
merged 2 commits into from
Oct 8, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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<[Element]> for List {
fn as_ref(&self) -> &[Element] {
&self.0.as_ref()

Check failure on line 57 in src/types/list.rs

View workflow job for this annotation

GitHub Actions / Build and Test (ubuntu, all)

this expression creates a reference which is immediately dereferenced by the compiler

Check failure on line 57 in src/types/list.rs

View workflow job for this annotation

GitHub Actions / Build and Test (ubuntu, all)

this expression creates a reference which is immediately dereferenced by the compiler
}
}

// 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<[Element]> for SExp {
fn as_ref(&self) -> &[Element] {
&self.0.as_ref()

Check failure on line 57 in src/types/sexp.rs

View workflow job for this annotation

GitHub Actions / Build and Test (ubuntu, all)

this expression creates a reference which is immediately dereferenced by the compiler

Check failure on line 57 in src/types/sexp.rs

View workflow job for this annotation

GitHub Actions / Build and Test (ubuntu, all)

this expression creates a reference which is immediately dereferenced by the compiler
}
}

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