Be less verbose when constructing an object
The rust compiler does some fancy things for us: It automatically finds the right fields if the name of the variable and the file is the same. Lets use that to reduce boilerplate with this patch.
This commit is contained in:
parent
154c2e482b
commit
84249e3fb5
7 changed files with 11 additions and 27 deletions
|
@ -143,7 +143,7 @@ pub trait TraceIterator<T, E> : Iterator<Item = Result<T, E>> + Sized {
|
|||
fn unwrap_with<F>(self, f: F) -> UnwrapWith<Self, F>
|
||||
where F: FnMut(E)
|
||||
{
|
||||
UnwrapWith { iter: self, f: f }
|
||||
UnwrapWith { iter: self, f }
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -148,7 +148,7 @@ impl StoreEntry {
|
|||
}
|
||||
|
||||
Ok(StoreEntry {
|
||||
id: id,
|
||||
id,
|
||||
file: backend.new_instance(pb),
|
||||
status: StoreEntryStatus::Present,
|
||||
})
|
||||
|
@ -758,10 +758,7 @@ impl<'a> FileLockEntry<'a, > {
|
|||
///
|
||||
/// Only for internal use.
|
||||
fn new(store: &'a Store, entry: Entry) -> FileLockEntry<'a> {
|
||||
FileLockEntry {
|
||||
store: store,
|
||||
entry: entry,
|
||||
}
|
||||
FileLockEntry { store, entry }
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -883,8 +880,8 @@ impl Entry {
|
|||
|
||||
Ok(Entry {
|
||||
location: loc.into_storeid()?,
|
||||
header: header,
|
||||
content: content,
|
||||
header,
|
||||
content,
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
@ -80,7 +80,7 @@ impl StoreId {
|
|||
debug!("Building Storeid object baseless");
|
||||
Ok(StoreId {
|
||||
base: None,
|
||||
id: id
|
||||
id
|
||||
})
|
||||
}
|
||||
}
|
||||
|
@ -255,9 +255,7 @@ impl Debug for StoreIdIterator {
|
|||
impl StoreIdIterator {
|
||||
|
||||
pub fn new(iter: Box<Iterator<Item = StoreId>>) -> StoreIdIterator {
|
||||
StoreIdIterator {
|
||||
iter: iter,
|
||||
}
|
||||
StoreIdIterator { iter }
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -44,7 +44,7 @@ pub mod err {
|
|||
impl ErrorNotification {
|
||||
pub fn new(trace: usize, timeout: i32) -> ErrorNotification {
|
||||
let notif = Notification {
|
||||
timeout: timeout,
|
||||
timeout,
|
||||
message: String::new(), // Not used in this special case
|
||||
summary: "[Error]".to_owned(),
|
||||
urgency: Urgency::High,
|
||||
|
|
|
@ -30,11 +30,7 @@ pub struct Date {
|
|||
impl Date {
|
||||
|
||||
pub fn new(year: i32, month: u32, day: u32) -> Date {
|
||||
Date {
|
||||
year: year,
|
||||
month: month,
|
||||
day: day,
|
||||
}
|
||||
Date { year, month, day }
|
||||
}
|
||||
|
||||
pub fn year(&self) -> i32 {
|
||||
|
|
|
@ -31,10 +31,7 @@ pub struct DateTime {
|
|||
impl DateTime {
|
||||
|
||||
pub fn new(date: Date, time: Time) -> DateTime {
|
||||
DateTime {
|
||||
date: date,
|
||||
time: time
|
||||
}
|
||||
DateTime { date, time }
|
||||
}
|
||||
|
||||
pub fn date(&self) -> &Date {
|
||||
|
|
|
@ -30,11 +30,7 @@ pub struct Time {
|
|||
impl Time {
|
||||
|
||||
pub fn new(hour: u32, minute: u32, second: u32) -> Time {
|
||||
Time {
|
||||
hour: hour,
|
||||
minute: minute,
|
||||
second: second
|
||||
}
|
||||
Time { hour, minute, second }
|
||||
}
|
||||
|
||||
pub fn hour(&self) -> u32 {
|
||||
|
|
Loading…
Reference in a new issue