Skip to content

Commit

Permalink
Add test for struct holding original data and a struct which holds a …
Browse files Browse the repository at this point in the history
…reference to original data. (#130)

* Add test for struct holding original data and a struct which holds a reference to original data.

* Update original data and struct holding reference to original data

* reduce scope a bit of test
  • Loading branch information
PLeVasseur authored Jan 11, 2025
1 parent a8cd334 commit cb51167
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions examples/src/ok_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,24 @@ struct DeriveCompilesOk<T: 'static> {
// y: &'this (),
// }

struct PhraseRef<'a> {
data: &'a mut String,
}

impl<'a> PhraseRef<'a> {
fn change_phrase(&mut self) {
*self.data = self.data.replace("Hello", "Goodbye");
}
}

#[self_referencing]
struct DataAndCustomRef {
data: String,
#[borrows(mut data)]
#[not_covariant]
phrase: PhraseRef<'this>,
}

#[test]
fn box_and_ref() {
let bar = BoxAndRefBuilder {
Expand Down Expand Up @@ -272,6 +290,18 @@ fn double_lifetime() {
}
}

#[test]
fn custom_ref() {
let mut instance = DataAndCustomRefBuilder {
data: "Hello world!".to_owned(),
phrase_builder: |data| PhraseRef { data },
}
.build();
instance.with_phrase_mut(|phrase| phrase.change_phrase());
let modified_data = instance.into_heads().data;
assert_eq!(modified_data, "Goodbye world!");
}

#[cfg(not(feature = "miri"))]
#[rustversion::stable(1.62)]
mod compile_tests {
Expand Down

0 comments on commit cb51167

Please sign in to comment.