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>
|
fn unwrap_with<F>(self, f: F) -> UnwrapWith<Self, F>
|
||||||
where F: FnMut(E)
|
where F: FnMut(E)
|
||||||
{
|
{
|
||||||
UnwrapWith { iter: self, f: f }
|
UnwrapWith { iter: self, f }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -148,7 +148,7 @@ impl StoreEntry {
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(StoreEntry {
|
Ok(StoreEntry {
|
||||||
id: id,
|
id,
|
||||||
file: backend.new_instance(pb),
|
file: backend.new_instance(pb),
|
||||||
status: StoreEntryStatus::Present,
|
status: StoreEntryStatus::Present,
|
||||||
})
|
})
|
||||||
|
@ -758,10 +758,7 @@ impl<'a> FileLockEntry<'a, > {
|
||||||
///
|
///
|
||||||
/// Only for internal use.
|
/// Only for internal use.
|
||||||
fn new(store: &'a Store, entry: Entry) -> FileLockEntry<'a> {
|
fn new(store: &'a Store, entry: Entry) -> FileLockEntry<'a> {
|
||||||
FileLockEntry {
|
FileLockEntry { store, entry }
|
||||||
store: store,
|
|
||||||
entry: entry,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -883,8 +880,8 @@ impl Entry {
|
||||||
|
|
||||||
Ok(Entry {
|
Ok(Entry {
|
||||||
location: loc.into_storeid()?,
|
location: loc.into_storeid()?,
|
||||||
header: header,
|
header,
|
||||||
content: content,
|
content,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -80,7 +80,7 @@ impl StoreId {
|
||||||
debug!("Building Storeid object baseless");
|
debug!("Building Storeid object baseless");
|
||||||
Ok(StoreId {
|
Ok(StoreId {
|
||||||
base: None,
|
base: None,
|
||||||
id: id
|
id
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -255,9 +255,7 @@ impl Debug for StoreIdIterator {
|
||||||
impl StoreIdIterator {
|
impl StoreIdIterator {
|
||||||
|
|
||||||
pub fn new(iter: Box<Iterator<Item = StoreId>>) -> StoreIdIterator {
|
pub fn new(iter: Box<Iterator<Item = StoreId>>) -> StoreIdIterator {
|
||||||
StoreIdIterator {
|
StoreIdIterator { iter }
|
||||||
iter: iter,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -44,7 +44,7 @@ pub mod err {
|
||||||
impl ErrorNotification {
|
impl ErrorNotification {
|
||||||
pub fn new(trace: usize, timeout: i32) -> ErrorNotification {
|
pub fn new(trace: usize, timeout: i32) -> ErrorNotification {
|
||||||
let notif = Notification {
|
let notif = Notification {
|
||||||
timeout: timeout,
|
timeout,
|
||||||
message: String::new(), // Not used in this special case
|
message: String::new(), // Not used in this special case
|
||||||
summary: "[Error]".to_owned(),
|
summary: "[Error]".to_owned(),
|
||||||
urgency: Urgency::High,
|
urgency: Urgency::High,
|
||||||
|
|
|
@ -30,11 +30,7 @@ pub struct Date {
|
||||||
impl Date {
|
impl Date {
|
||||||
|
|
||||||
pub fn new(year: i32, month: u32, day: u32) -> Date {
|
pub fn new(year: i32, month: u32, day: u32) -> Date {
|
||||||
Date {
|
Date { year, month, day }
|
||||||
year: year,
|
|
||||||
month: month,
|
|
||||||
day: day,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn year(&self) -> i32 {
|
pub fn year(&self) -> i32 {
|
||||||
|
|
|
@ -31,10 +31,7 @@ pub struct DateTime {
|
||||||
impl DateTime {
|
impl DateTime {
|
||||||
|
|
||||||
pub fn new(date: Date, time: Time) -> DateTime {
|
pub fn new(date: Date, time: Time) -> DateTime {
|
||||||
DateTime {
|
DateTime { date, time }
|
||||||
date: date,
|
|
||||||
time: time
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn date(&self) -> &Date {
|
pub fn date(&self) -> &Date {
|
||||||
|
|
|
@ -30,11 +30,7 @@ pub struct Time {
|
||||||
impl Time {
|
impl Time {
|
||||||
|
|
||||||
pub fn new(hour: u32, minute: u32, second: u32) -> Time {
|
pub fn new(hour: u32, minute: u32, second: u32) -> Time {
|
||||||
Time {
|
Time { hour, minute, second }
|
||||||
hour: hour,
|
|
||||||
minute: minute,
|
|
||||||
second: second
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn hour(&self) -> u32 {
|
pub fn hour(&self) -> u32 {
|
||||||
|
|
Loading…
Reference in a new issue