Merge pull request #374 from matthiasbeyer/remove-unneeded-derefs
Remove unneeded derefs
This commit is contained in:
commit
0c4edf6474
6 changed files with 18 additions and 24 deletions
|
@ -39,7 +39,7 @@ pub fn retrieve(rt: &Runtime) {
|
||||||
fn print_entry(rt: &Runtime, scmd: &ArgMatches, e: FileLockEntry) {
|
fn print_entry(rt: &Runtime, scmd: &ArgMatches, e: FileLockEntry) {
|
||||||
if do_print_raw(scmd) {
|
if do_print_raw(scmd) {
|
||||||
debug!("Printing raw content...");
|
debug!("Printing raw content...");
|
||||||
println!("{}", e.deref().to_str());
|
println!("{}", e.to_str());
|
||||||
} else if do_filter(scmd) {
|
} else if do_filter(scmd) {
|
||||||
debug!("Filtering...");
|
debug!("Filtering...");
|
||||||
warn!("Filtering via header specs is currently now supported.");
|
warn!("Filtering via header specs is currently now supported.");
|
||||||
|
@ -47,7 +47,6 @@ fn print_entry(rt: &Runtime, scmd: &ArgMatches, e: FileLockEntry) {
|
||||||
unimplemented!()
|
unimplemented!()
|
||||||
} else {
|
} else {
|
||||||
debug!("Printing structured...");
|
debug!("Printing structured...");
|
||||||
let entry = e.deref();
|
|
||||||
if do_print_header(scmd) {
|
if do_print_header(scmd) {
|
||||||
debug!("Printing header...");
|
debug!("Printing header...");
|
||||||
if do_print_header_as_json(rt.cli()) {
|
if do_print_header_as_json(rt.cli()) {
|
||||||
|
@ -58,13 +57,13 @@ fn print_entry(rt: &Runtime, scmd: &ArgMatches, e: FileLockEntry) {
|
||||||
} else {
|
} else {
|
||||||
debug!("Printing header as TOML...");
|
debug!("Printing header as TOML...");
|
||||||
// We have to Value::Table() for Display
|
// We have to Value::Table() for Display
|
||||||
println!("{}", Value::Table(entry.get_header().clone().into()))
|
println!("{}", Value::Table(e.get_header().clone().into()))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if do_print_content(scmd) {
|
if do_print_content(scmd) {
|
||||||
debug!("Printing content...");
|
debug!("Printing content...");
|
||||||
println!("{}", entry.get_content());
|
println!("{}", e.get_content());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,7 +11,6 @@
|
||||||
/// This helps us greatly with deduplication of URLs.
|
/// This helps us greatly with deduplication of URLs.
|
||||||
///
|
///
|
||||||
|
|
||||||
use std::ops::Deref;
|
|
||||||
use std::ops::DerefMut;
|
use std::ops::DerefMut;
|
||||||
use std::collections::BTreeMap;
|
use std::collections::BTreeMap;
|
||||||
|
|
||||||
|
@ -60,8 +59,7 @@ impl<'a> Link<'a> {
|
||||||
|
|
||||||
/// Get a link Url object from a FileLockEntry, ignore errors.
|
/// Get a link Url object from a FileLockEntry, ignore errors.
|
||||||
fn get_link_uri_from_filelockentry(file: &FileLockEntry<'a>) -> Option<Url> {
|
fn get_link_uri_from_filelockentry(file: &FileLockEntry<'a>) -> Option<Url> {
|
||||||
file.deref()
|
file.get_header()
|
||||||
.get_header()
|
|
||||||
.read("imag.content.uri")
|
.read("imag.content.uri")
|
||||||
.ok()
|
.ok()
|
||||||
.and_then(|opt| {
|
.and_then(|opt| {
|
||||||
|
@ -74,7 +72,6 @@ impl<'a> Link<'a> {
|
||||||
|
|
||||||
pub fn get_url(&self) -> Result<Option<Url>> {
|
pub fn get_url(&self) -> Result<Option<Url>> {
|
||||||
let opt = self.link
|
let opt = self.link
|
||||||
.deref()
|
|
||||||
.get_header()
|
.get_header()
|
||||||
.read("imag.content.uri");
|
.read("imag.content.uri");
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
use std::io::stdout;
|
use std::io::stdout;
|
||||||
use std::io::Write;
|
use std::io::Write;
|
||||||
use std::ops::Deref;
|
|
||||||
|
|
||||||
use lister::Lister;
|
use lister::Lister;
|
||||||
use result::Result;
|
use result::Result;
|
||||||
|
@ -30,7 +29,7 @@ impl<'a> Lister for CoreLister<'a> {
|
||||||
|
|
||||||
entries.fold(Ok(()), |accu, entry| {
|
entries.fold(Ok(()), |accu, entry| {
|
||||||
accu.and_then(|_| {
|
accu.and_then(|_| {
|
||||||
write!(stdout(), "{:?}\n", (self.lister)(entry.deref()))
|
write!(stdout(), "{:?}\n", (self.lister)(&entry))
|
||||||
.map_err(|e| LE::new(LEK::FormatError, Some(Box::new(e))))
|
.map_err(|e| LE::new(LEK::FormatError, Some(Box::new(e))))
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
use std::io::stdout;
|
use std::io::stdout;
|
||||||
use std::io::Write;
|
use std::io::Write;
|
||||||
use std::ops::Deref;
|
|
||||||
|
|
||||||
use lister::Lister;
|
use lister::Lister;
|
||||||
use result::Result;
|
use result::Result;
|
||||||
|
@ -28,7 +27,7 @@ impl Lister for PathLister {
|
||||||
use error::ListErrorKind as LEK;
|
use error::ListErrorKind as LEK;
|
||||||
|
|
||||||
entries.fold(Ok(()), |accu, entry| {
|
entries.fold(Ok(()), |accu, entry| {
|
||||||
accu.and_then(|_| Ok(entry.deref().get_location().clone()))
|
accu.and_then(|_| Ok(entry.get_location().clone()))
|
||||||
.and_then(|pb| {
|
.and_then(|pb| {
|
||||||
if self.absolute {
|
if self.absolute {
|
||||||
pb.canonicalize().map_err(|e| LE::new(LEK::FormatError, Some(Box::new(e))))
|
pb.canonicalize().map_err(|e| LE::new(LEK::FormatError, Some(Box::new(e))))
|
||||||
|
|
|
@ -64,14 +64,14 @@ impl<'a> Note<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_name(&mut self, n: String) -> Result<()> {
|
pub fn set_name(&mut self, n: String) -> Result<()> {
|
||||||
let mut header = self.entry.deref_mut().get_header_mut();
|
let mut header = self.entry.get_header_mut();
|
||||||
header.set("note.name", Value::String(n))
|
header.set("note.name", Value::String(n))
|
||||||
.map_err(|e| NE::new(NEK::StoreWriteError, Some(Box::new(e))))
|
.map_err(|e| NE::new(NEK::StoreWriteError, Some(Box::new(e))))
|
||||||
.map(|_| ())
|
.map(|_| ())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_name(&self) -> Result<String> {
|
pub fn get_name(&self) -> Result<String> {
|
||||||
let header = self.entry.deref().get_header();
|
let header = self.entry.get_header();
|
||||||
match header.read("note.name") {
|
match header.read("note.name") {
|
||||||
Ok(Some(Value::String(s))) => Ok(String::from(s)),
|
Ok(Some(Value::String(s))) => Ok(String::from(s)),
|
||||||
Ok(_) => {
|
Ok(_) => {
|
||||||
|
@ -83,11 +83,11 @@ impl<'a> Note<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_text(&mut self, n: String) {
|
pub fn set_text(&mut self, n: String) {
|
||||||
*self.entry.deref_mut().get_content_mut() = n
|
*self.entry.get_content_mut() = n
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_text(&self) -> &String {
|
pub fn get_text(&self) -> &String {
|
||||||
self.entry.deref().get_content()
|
self.entry.get_content()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn delete(store: &Store, name: String) -> Result<()> {
|
pub fn delete(store: &Store, name: String) -> Result<()> {
|
||||||
|
@ -120,27 +120,27 @@ impl<'a> Edit for Note<'a> {
|
||||||
impl<'a> Tagable for Note<'a> {
|
impl<'a> Tagable for Note<'a> {
|
||||||
|
|
||||||
fn get_tags(&self) -> TagResult<Vec<Tag>> {
|
fn get_tags(&self) -> TagResult<Vec<Tag>> {
|
||||||
self.entry.deref().get_tags()
|
self.entry.get_tags()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn set_tags(&mut self, ts: Vec<Tag>) -> TagResult<()> {
|
fn set_tags(&mut self, ts: Vec<Tag>) -> TagResult<()> {
|
||||||
self.entry.deref_mut().set_tags(ts)
|
self.entry.set_tags(ts)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn add_tag(&mut self, t: Tag) -> TagResult<()> {
|
fn add_tag(&mut self, t: Tag) -> TagResult<()> {
|
||||||
self.entry.deref_mut().add_tag(t)
|
self.entry.add_tag(t)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn remove_tag(&mut self, t: Tag) -> TagResult<()> {
|
fn remove_tag(&mut self, t: Tag) -> TagResult<()> {
|
||||||
self.entry.deref_mut().remove_tag(t)
|
self.entry.remove_tag(t)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn has_tag(&self, t: &Tag) -> TagResult<bool> {
|
fn has_tag(&self, t: &Tag) -> TagResult<bool> {
|
||||||
self.entry.deref().has_tag(t)
|
self.entry.has_tag(t)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn has_tags(&self, ts: &Vec<Tag>) -> TagResult<bool> {
|
fn has_tags(&self, ts: &Vec<Tag>) -> TagResult<bool> {
|
||||||
self.entry.deref().has_tags(ts)
|
self.entry.has_tags(ts)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -553,7 +553,7 @@ impl<'a> FileLockEntry<'a, > {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> ::std::ops::Deref for FileLockEntry<'a> {
|
impl<'a> Deref for FileLockEntry<'a> {
|
||||||
type Target = Entry;
|
type Target = Entry;
|
||||||
|
|
||||||
fn deref(&self) -> &Self::Target {
|
fn deref(&self) -> &Self::Target {
|
||||||
|
@ -561,7 +561,7 @@ impl<'a> ::std::ops::Deref for FileLockEntry<'a> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> ::std::ops::DerefMut for FileLockEntry<'a> {
|
impl<'a> DerefMut for FileLockEntry<'a> {
|
||||||
fn deref_mut(&mut self) -> &mut Self::Target {
|
fn deref_mut(&mut self) -> &mut Self::Target {
|
||||||
&mut self.entry
|
&mut self.entry
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue