summaryrefslogtreecommitdiff
path: root/copypasta
diff options
context:
space:
mode:
authorChristian Duerr <chrisduerr@users.noreply.github.com>2019-03-30 16:48:36 +0000
committerGitHub <noreply@github.com>2019-03-30 16:48:36 +0000
commitcfd025b5289bc305470a96657868c982a2b13bc2 (patch)
tree093b9105c881e28b909e031c46d2054016b643b3 /copypasta
parent91aa683bcd060b2ac2f621a388a6448f564d0537 (diff)
downloadalacritty-cfd025b5289bc305470a96657868c982a2b13bc2.tar.gz
alacritty-cfd025b5289bc305470a96657868c982a2b13bc2.zip
Add rustfmt style guidev0.3.0-rc1
Diffstat (limited to 'copypasta')
-rw-r--r--copypasta/src/macos.rs46
-rw-r--r--copypasta/src/windows.rs12
-rw-r--r--copypasta/src/x11.rs48
3 files changed, 41 insertions, 65 deletions
diff --git a/copypasta/src/macos.rs b/copypasta/src/macos.rs
index 1942ac43..d0ccaec4 100644
--- a/copypasta/src/macos.rs
+++ b/copypasta/src/macos.rs
@@ -4,18 +4,18 @@
//! https://developer.apple.com/library/content/documentation/Cocoa/Conceptual/PasteboardGuide106/Articles/pbReading.html#//apple_ref/doc/uid/TP40008123-SW1
mod ns {
- extern crate objc_id;
extern crate objc_foundation;
+ extern crate objc_id;
#[link(name = "AppKit", kind = "framework")]
- extern {}
+ extern "C" {}
use std::mem;
- use objc::runtime::{Class, Object};
+ use self::objc_foundation::{INSArray, INSObject, INSString};
+ use self::objc_foundation::{NSArray, NSDictionary, NSObject, NSString};
use self::objc_id::{Id, Owned};
- use self::objc_foundation::{NSArray, NSObject, NSDictionary, NSString};
- use self::objc_foundation::{INSString, INSArray, INSObject};
+ use objc::runtime::{Class, Object};
/// Rust API for NSPasteboard
pub struct Pasteboard(Id<Object>);
@@ -55,6 +55,7 @@ mod ns {
impl PasteboardReadObject<String> for Pasteboard {
type Err = ReadStringError;
+
fn read_object(&self) -> Result<String, ReadStringError> {
// Get string class; need this for passing to readObjectsForClasses
let ns_string_class = match Class::get("NSString") {
@@ -133,9 +134,7 @@ mod ns {
// The writeObjects method returns true in case of success, and
// false otherwise.
- let ok: bool = unsafe {
- msg_send![self.0, writeObjects:objects]
- };
+ let ok: bool = unsafe { msg_send![self.0, writeObjects: objects] };
if ok {
Ok(())
@@ -175,9 +174,7 @@ mod ns {
impl ::std::error::Error for NewPasteboardError {
fn description(&self) -> &str {
match *self {
- NewPasteboardError::GetPasteboardClass => {
- "NSPasteboard class not found"
- },
+ NewPasteboardError::GetPasteboardClass => "NSPasteboard class not found",
NewPasteboardError::LoadGeneralPasteboard => {
"[NSPasteboard generalPasteboard] failed"
},
@@ -209,9 +206,7 @@ mod ns {
}
};
- let id = unsafe {
- Id::from_ptr(ptr)
- };
+ let id = unsafe { Id::from_ptr(ptr) };
Ok(Pasteboard(id))
}
@@ -222,9 +217,7 @@ mod ns {
/// This is the first step in providing data on the pasteboard. The
/// return value is the change count of the pasteboard
pub fn clear_contents(&mut self) -> usize {
- unsafe {
- msg_send![self.0, clearContents]
- }
+ unsafe { msg_send![self.0, clearContents] }
}
}
}
@@ -236,7 +229,6 @@ pub enum Error {
WriteString(ns::WriteStringError),
}
-
impl ::std::error::Error for Error {
fn cause(&self) -> Option<&::std::error::Error> {
match *self {
@@ -258,9 +250,7 @@ impl ::std::error::Error for Error {
impl ::std::fmt::Display for Error {
fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result {
match *self {
- Error::CreatePasteboard(ref err) => {
- write!(f, "Failed to create pasteboard: {}", err)
- },
+ Error::CreatePasteboard(ref err) => write!(f, "Failed to create pasteboard: {}", err),
Error::ReadString(ref err) => {
write!(f, "Failed to read string from pasteboard: {}", err)
},
@@ -301,23 +291,23 @@ impl super::Load for Clipboard {
fn load_primary(&self) -> Result<String, Self::Err> {
use self::ns::PasteboardReadObject;
- self.0.read_object()
- .map_err(::std::convert::From::from)
+ self.0.read_object().map_err(::std::convert::From::from)
}
}
impl super::Store for Clipboard {
fn store_primary<S>(&mut self, contents: S) -> Result<(), Self::Err>
- where S: Into<String>
+ where
+ S: Into<String>,
{
use self::ns::PasteboardWriteObject;
- self.0.write_object(contents.into())
- .map_err(::std::convert::From::from)
+ self.0.write_object(contents.into()).map_err(::std::convert::From::from)
}
fn store_selection<S>(&mut self, _contents: S) -> Result<(), Self::Err>
- where S: Into<String>
+ where
+ S: Into<String>,
{
// No such thing on macOS
Ok(())
@@ -327,7 +317,7 @@ impl super::Store for Clipboard {
#[cfg(test)]
mod tests {
use super::Clipboard;
- use ::{Load, Store};
+ use {Load, Store};
#[test]
fn create_clipboard_save_load_contents() {
diff --git a/copypasta/src/windows.rs b/copypasta/src/windows.rs
index 95e3db55..48b033cc 100644
--- a/copypasta/src/windows.rs
+++ b/copypasta/src/windows.rs
@@ -33,9 +33,7 @@ impl Load for Clipboard {
type Err = Error;
fn new() -> Result<Self, Error> {
- ClipboardContext::new()
- .map(Clipboard)
- .map_err(Error::Clipboard)
+ ClipboardContext::new().map(Clipboard).map_err(Error::Clipboard)
}
fn load_primary(&self) -> Result<String, Self::Err> {
@@ -56,9 +54,7 @@ impl Store for Clipboard {
where
S: Into<String>,
{
- self.0
- .set_contents(contents.into())
- .map_err(Error::Clipboard)
+ self.0.set_contents(contents.into()).map_err(Error::Clipboard)
}
/// Sets the secondary clipboard contents
@@ -67,8 +63,6 @@ impl Store for Clipboard {
where
S: Into<String>,
{
- self.0
- .set_contents(contents.into())
- .map_err(Error::Clipboard)
+ self.0.set_contents(contents.into()).map_err(Error::Clipboard)
}
}
diff --git a/copypasta/src/x11.rs b/copypasta/src/x11.rs
index c7d9c696..3e0d7913 100644
--- a/copypasta/src/x11.rs
+++ b/copypasta/src/x11.rs
@@ -7,10 +7,10 @@
//!
//! FIXME: Implement actual X11 clipboard API using the ICCCM reference
//! https://tronche.com/gui/x/icccm/
+use std::ffi::OsStr;
use std::io;
-use std::process::{Output, Command};
+use std::process::{Command, Output};
use std::string::FromUtf8Error;
-use std::ffi::OsStr;
use super::{Load, Store};
@@ -45,13 +45,11 @@ impl ::std::error::Error for Error {
impl ::std::fmt::Display for Error {
fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result {
match *self {
- Error::Io(ref err) => {
- match err.kind() {
- io::ErrorKind::NotFound => {
- write!(f, "Please install `xclip` to enable clipboard support")
- },
- _ => write!(f, "Error calling xclip: {}", err),
- }
+ Error::Io(ref err) => match err.kind() {
+ io::ErrorKind::NotFound => {
+ write!(f, "Please install `xclip` to enable clipboard support")
+ },
+ _ => write!(f, "Error calling xclip: {}", err),
},
Error::Xclip(ref s) => write!(f, "Error from xclip: {}", s),
Error::Utf8(ref err) => write!(f, "Error parsing xclip output: {}", err),
@@ -79,17 +77,13 @@ impl Load for Clipboard {
}
fn load_primary(&self) -> Result<String, Self::Err> {
- let output = Command::new("xclip")
- .args(&["-o", "-selection", "clipboard"])
- .output()?;
+ let output = Command::new("xclip").args(&["-o", "-selection", "clipboard"]).output()?;
Clipboard::process_xclip_output(output)
}
fn load_selection(&self) -> Result<String, Self::Err> {
- let output = Command::new("xclip")
- .args(&["-o"])
- .output()?;
+ let output = Command::new("xclip").args(&["-o"]).output()?;
Clipboard::process_xclip_output(output)
}
@@ -99,7 +93,8 @@ impl Store for Clipboard {
/// Sets the primary clipboard contents
#[inline]
fn store_primary<S>(&mut self, contents: S) -> Result<(), Self::Err>
- where S: Into<String>
+ where
+ S: Into<String>,
{
self.store(contents, &["-i", "-selection", "clipboard"])
}
@@ -107,7 +102,8 @@ impl Store for Clipboard {
/// Sets the secondary clipboard contents
#[inline]
fn store_selection<S>(&mut self, contents: S) -> Result<(), Self::Err>
- where S: Into<String>
+ where
+ S: Into<String>,
{
self.store(contents, &["-i"])
}
@@ -116,26 +112,22 @@ impl Store for Clipboard {
impl Clipboard {
fn process_xclip_output(output: Output) -> Result<String, Error> {
if output.status.success() {
- String::from_utf8(output.stdout)
- .map_err(::std::convert::From::from)
+ String::from_utf8(output.stdout).map_err(::std::convert::From::from)
} else {
- String::from_utf8(output.stderr)
- .map_err(::std::convert::From::from)
+ String::from_utf8(output.stderr).map_err(::std::convert::From::from)
}
}
fn store<C, S>(&mut self, contents: C, args: &[S]) -> Result<(), Error>
- where C: Into<String>,
- S: AsRef<OsStr>,
+ where
+ C: Into<String>,
+ S: AsRef<OsStr>,
{
use std::io::Write;
use std::process::{Command, Stdio};
let contents = contents.into();
- let mut child = Command::new("xclip")
- .args(args)
- .stdin(Stdio::piped())
- .spawn()?;
+ let mut child = Command::new("xclip").args(args).stdin(Stdio::piped()).spawn()?;
if let Some(stdin) = child.stdin.as_mut() {
stdin.write_all(contents.as_bytes())?;
@@ -154,7 +146,7 @@ impl Clipboard {
#[cfg(test)]
mod tests {
use super::Clipboard;
- use ::{Load, Store};
+ use {Load, Store};
#[test]
fn clipboard_works() {