Skip to content

Commit 66f3e4e

Browse files
committed
journal: take mutable references for C interior mutability
This commit changes some methods signature to take mutable references wherever the FFI implies some internal status mutation by the C API. While this is not stricly needed by Rust rules, it helps in explicitly conveying the semantic across the layers.
1 parent af785fb commit 66f3e4e

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

src/journal.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ impl Journal {
153153

154154
/// Read the next record from the journal. Returns `Ok(None)` if there
155155
/// are no more records to read.
156-
pub fn next_record(&self) -> Result<Option<JournalRecord>> {
156+
pub fn next_record(&mut self) -> Result<Option<JournalRecord>> {
157157
if sd_try!(ffi::sd_journal_next(self.j)) == 0 {
158158
return Ok(None);
159159
}
@@ -179,7 +179,7 @@ impl Journal {
179179

180180
/// Seek to a specific position in journal. On success, returns a cursor
181181
/// to the current entry.
182-
pub fn seek(&self, seek: JournalSeek) -> Result<String> {
182+
pub fn seek(&mut self, seek: JournalSeek) -> Result<String> {
183183
match seek {
184184
JournalSeek::Head => sd_try!(ffi::sd_journal_seek_head(self.j)),
185185
JournalSeek::Current => 0,

tests/journal.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ fn cursor() {
3535
return;
3636
}
3737

38-
let j = journal::Journal::open(journal::JournalFiles::All, false, false).unwrap();
38+
let mut j = journal::Journal::open(journal::JournalFiles::All, false, false).unwrap();
3939
log!(log::LogLevel::Info, "rust-systemd test_seek entry");
4040
assert!(j.seek(journal::JournalSeek::Head).is_ok());
4141
let _s = j.cursor().unwrap();
@@ -47,7 +47,7 @@ fn ts() {
4747
return;
4848
}
4949

50-
let j = journal::Journal::open(journal::JournalFiles::All, false, false).unwrap();
50+
let mut j = journal::Journal::open(journal::JournalFiles::All, false, false).unwrap();
5151
log!(log::LogLevel::Info, "rust-systemd test_seek entry");
5252
assert!(j.seek(journal::JournalSeek::Head).is_ok());
5353
let _s = j.timestamp().unwrap();
@@ -56,7 +56,7 @@ fn ts() {
5656

5757
#[test]
5858
fn test_seek() {
59-
let j = journal::Journal::open(journal::JournalFiles::All, false, false).unwrap();
59+
let mut j = journal::Journal::open(journal::JournalFiles::All, false, false).unwrap();
6060
if ! have_journal() {
6161
return;
6262
}

0 commit comments

Comments
 (0)