rust: Use 2018 eition
This edition has better syntax around scoping and `use`.
This commit is contained in:
@ -1,6 +1,7 @@
|
||||
[package]
|
||||
name = "rs"
|
||||
version = "0.1.0"
|
||||
edition = "2018"
|
||||
|
||||
[lib]
|
||||
name = "rs"
|
||||
|
||||
@ -192,7 +192,7 @@ fn iter_layout_sources(
|
||||
}
|
||||
|
||||
fn load_layout_data(source: DataSource)
|
||||
-> Result<::layout::LayoutParseData, LoadError>
|
||||
-> Result<crate::layout::LayoutParseData, LoadError>
|
||||
{
|
||||
let handler = logging::Print {};
|
||||
match source {
|
||||
@ -268,7 +268,7 @@ pub fn load_layout(
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
use ::logging::ProblemPanic;
|
||||
use crate::logging::ProblemPanic;
|
||||
|
||||
#[test]
|
||||
fn parsing_fallback() {
|
||||
|
||||
@ -10,7 +10,7 @@ pub mod parsing;
|
||||
use std::io;
|
||||
use std::fmt;
|
||||
|
||||
use ::keyboard::FormattingError;
|
||||
use crate::keyboard::FormattingError;
|
||||
|
||||
/// Errors encountered loading the layout into yaml
|
||||
#[derive(Debug)]
|
||||
|
||||
@ -14,19 +14,19 @@ use xkbcommon::xkb;
|
||||
|
||||
use super::{ Error, LoadError };
|
||||
|
||||
use ::action;
|
||||
use crate::action;
|
||||
use crate::keyboard::{
|
||||
Key, generate_keymaps, generate_keycodes, KeyCode, FormattingError
|
||||
};
|
||||
use ::layout;
|
||||
use ::logging;
|
||||
use ::resources;
|
||||
use crate::layout;
|
||||
use crate::logging;
|
||||
use crate::resources;
|
||||
|
||||
// traits, derives
|
||||
use serde::Deserialize;
|
||||
use std::io::BufReader;
|
||||
use std::iter::FromIterator;
|
||||
use ::logging::Warn;
|
||||
use crate::logging::Warn;
|
||||
|
||||
// TODO: find a nice way to make sure non-positive sizes don't break layouts
|
||||
|
||||
@ -153,7 +153,7 @@ impl Layout {
|
||||
}
|
||||
|
||||
pub fn build<H: logging::Handler>(self, mut warning_handler: H)
|
||||
-> (Result<::layout::LayoutParseData, FormattingError>, H)
|
||||
-> (Result<crate::layout::LayoutParseData, FormattingError>, H)
|
||||
{
|
||||
let button_names = self.views.values()
|
||||
.flat_map(|rows| {
|
||||
@ -164,7 +164,7 @@ impl Layout {
|
||||
let button_names: HashSet<&str>
|
||||
= HashSet::from_iter(button_names);
|
||||
|
||||
let button_actions: Vec<(&str, ::action::Action)>
|
||||
let button_actions: Vec<(&str, crate::action::Action)>
|
||||
= button_names.iter().map(|name| {(
|
||||
*name,
|
||||
create_action(
|
||||
@ -182,7 +182,7 @@ impl Layout {
|
||||
let button_states = HashMap::<String, Key>::from_iter(
|
||||
button_actions.into_iter().map(|(name, action)| {
|
||||
let keycodes = match &action {
|
||||
::action::Action::Submit { text: _, keys } => {
|
||||
crate::action::Action::Submit { text: _, keys } => {
|
||||
keys.iter().map(|named_keysym| {
|
||||
symbolmap.get(named_keysym.0.as_str())
|
||||
.expect(
|
||||
@ -292,7 +292,7 @@ fn create_action<H: logging::Handler>(
|
||||
name: &str,
|
||||
view_names: Vec<&String>,
|
||||
warning_handler: &mut H,
|
||||
) -> ::action::Action {
|
||||
) -> crate::action::Action {
|
||||
let default_meta = ButtonMeta::default();
|
||||
let symbol_meta = button_info.get(name)
|
||||
.unwrap_or(&default_meta);
|
||||
@ -356,7 +356,7 @@ fn create_action<H: logging::Handler>(
|
||||
match submission {
|
||||
SubmitData::Action(
|
||||
Action::SetView(view_name)
|
||||
) => ::action::Action::SetView(
|
||||
) => crate::action::Action::SetView(
|
||||
filter_view_name(
|
||||
name, view_name.clone(), &view_names,
|
||||
warning_handler,
|
||||
@ -366,7 +366,7 @@ fn create_action<H: logging::Handler>(
|
||||
lock_view, unlock_view,
|
||||
pops,
|
||||
looks_locked_from,
|
||||
}) => ::action::Action::LockView {
|
||||
}) => crate::action::Action::LockView {
|
||||
lock: filter_view_name(
|
||||
name,
|
||||
lock_view.clone(),
|
||||
@ -384,11 +384,11 @@ fn create_action<H: logging::Handler>(
|
||||
},
|
||||
SubmitData::Action(
|
||||
Action::ShowPrefs
|
||||
) => ::action::Action::ShowPreferences,
|
||||
) => crate::action::Action::ShowPreferences,
|
||||
SubmitData::Action(Action::Erase) => action::Action::Erase,
|
||||
SubmitData::Keysym(keysym) => ::action::Action::Submit {
|
||||
SubmitData::Keysym(keysym) => crate::action::Action::Submit {
|
||||
text: None,
|
||||
keys: vec!(::action::KeySym(
|
||||
keys: vec!(crate::action::KeySym(
|
||||
match keysym_valid(keysym.as_str()) {
|
||||
true => keysym.clone(),
|
||||
false => {
|
||||
@ -404,7 +404,7 @@ fn create_action<H: logging::Handler>(
|
||||
}
|
||||
)),
|
||||
},
|
||||
SubmitData::Text(text) => ::action::Action::Submit {
|
||||
SubmitData::Text(text) => crate::action::Action::Submit {
|
||||
text: CString::new(text.clone()).or_warn(
|
||||
warning_handler,
|
||||
logging::Problem::Warning,
|
||||
@ -412,7 +412,7 @@ fn create_action<H: logging::Handler>(
|
||||
),
|
||||
keys: text.chars().map(|codepoint| {
|
||||
let codepoint_string = codepoint.to_string();
|
||||
::action::KeySym(match keysym_valid(codepoint_string.as_str()) {
|
||||
crate::action::KeySym(match keysym_valid(codepoint_string.as_str()) {
|
||||
true => codepoint_string,
|
||||
false => format!("U{:04X}", codepoint as u32),
|
||||
})
|
||||
@ -452,7 +452,7 @@ fn create_button<H: logging::Handler>(
|
||||
name: &str,
|
||||
data: Key,
|
||||
warning_handler: &mut H,
|
||||
) -> ::layout::Button {
|
||||
) -> crate::layout::Button {
|
||||
let cname = CString::new(name.clone())
|
||||
.expect("Bad name");
|
||||
// don't remove, because multiple buttons with the same name are allowed
|
||||
@ -462,13 +462,13 @@ fn create_button<H: logging::Handler>(
|
||||
|
||||
// TODO: move conversion to the C/Rust boundary
|
||||
let label = if let Some(label) = &button_meta.label {
|
||||
::layout::Label::Text(CString::new(label.as_str())
|
||||
crate::layout::Label::Text(CString::new(label.as_str())
|
||||
.expect("Bad label"))
|
||||
} else if let Some(icon) = &button_meta.icon {
|
||||
::layout::Label::IconName(CString::new(icon.as_str())
|
||||
crate::layout::Label::IconName(CString::new(icon.as_str())
|
||||
.expect("Bad icon"))
|
||||
} else if let Some(text) = &button_meta.text {
|
||||
::layout::Label::Text(
|
||||
crate::layout::Label::Text(
|
||||
CString::new(text.as_str())
|
||||
.or_warn(
|
||||
warning_handler,
|
||||
@ -477,7 +477,7 @@ fn create_button<H: logging::Handler>(
|
||||
).unwrap_or_else(|| CString::new("").unwrap())
|
||||
)
|
||||
} else {
|
||||
::layout::Label::Text(cname.clone())
|
||||
crate::layout::Label::Text(cname.clone())
|
||||
};
|
||||
|
||||
let outline_name = match &button_meta.outline {
|
||||
@ -541,7 +541,7 @@ mod tests {
|
||||
|
||||
use std::env;
|
||||
|
||||
use ::logging::ProblemPanic;
|
||||
use crate::logging::ProblemPanic;
|
||||
|
||||
fn path_from_root(file: &'static str) -> PathBuf {
|
||||
let source_dir = env::var("SOURCE_DIR")
|
||||
@ -637,7 +637,7 @@ mod tests {
|
||||
.get_rows()[0].1
|
||||
.get_buttons()[0].1
|
||||
.label,
|
||||
::layout::Label::Text(CString::new("test").unwrap())
|
||||
crate::layout::Label::Text(CString::new("test").unwrap())
|
||||
);
|
||||
}
|
||||
|
||||
@ -652,7 +652,7 @@ mod tests {
|
||||
.get_rows()[0].1
|
||||
.get_buttons()[0].1
|
||||
.label,
|
||||
::layout::Label::Text(CString::new("test").unwrap())
|
||||
crate::layout::Label::Text(CString::new("test").unwrap())
|
||||
);
|
||||
}
|
||||
|
||||
@ -717,9 +717,9 @@ mod tests {
|
||||
Vec::new(),
|
||||
&mut ProblemPanic,
|
||||
),
|
||||
::action::Action::Submit {
|
||||
crate::action::Action::Submit {
|
||||
text: Some(CString::new(".").unwrap()),
|
||||
keys: vec!(::action::KeySym("U002E".into())),
|
||||
keys: vec!(crate::action::KeySym("U002E".into())),
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
@ -2,11 +2,11 @@
|
||||
|
||||
use cairo;
|
||||
|
||||
use ::action::{ Action, Modifier };
|
||||
use ::keyboard;
|
||||
use crate::action::{ Action, Modifier };
|
||||
use crate::keyboard;
|
||||
use crate::layout::{ Button, ButtonPosition, Label, LatchedState, Layout };
|
||||
use ::layout::c::{ Bounds, EekGtkKeyboard, Point };
|
||||
use ::submission::c::Submission as CSubmission;
|
||||
use crate::layout::c::{ Bounds, EekGtkKeyboard, Point };
|
||||
use crate::submission::c::Submission as CSubmission;
|
||||
|
||||
use glib::translate::FromGlibPtrNone;
|
||||
use gtk::prelude::WidgetExt;
|
||||
|
||||
@ -13,9 +13,9 @@
|
||||
|
||||
extern crate core;
|
||||
|
||||
use ::float_ord::core::cmp::{Eq, Ord, Ordering, PartialEq, PartialOrd};
|
||||
use ::float_ord::core::hash::{Hash, Hasher};
|
||||
use ::float_ord::core::mem::transmute;
|
||||
use crate::float_ord::core::cmp::{Eq, Ord, Ordering, PartialEq, PartialOrd};
|
||||
use crate::float_ord::core::hash::{Hash, Hasher};
|
||||
use crate::float_ord::core::mem::transmute;
|
||||
|
||||
/// A wrapper for floats, that implements total equality and ordering
|
||||
/// and hashing.
|
||||
@ -99,16 +99,16 @@ mod tests {
|
||||
assert!(FloatOrd(1.0f32) == FloatOrd(1.0f32));
|
||||
assert!(FloatOrd(0.0f64) > FloatOrd(-0.0f64));
|
||||
assert!(FloatOrd(0.0f32) > FloatOrd(-0.0f32));
|
||||
assert!(FloatOrd(::float_ord::core::f64::NAN) == FloatOrd(::float_ord::core::f64::NAN));
|
||||
assert!(FloatOrd(::float_ord::core::f32::NAN) == FloatOrd(::float_ord::core::f32::NAN));
|
||||
assert!(FloatOrd(-::float_ord::core::f64::NAN) < FloatOrd(::float_ord::core::f64::NAN));
|
||||
assert!(FloatOrd(-::float_ord::core::f32::NAN) < FloatOrd(::float_ord::core::f32::NAN));
|
||||
assert!(FloatOrd(-::float_ord::core::f64::INFINITY) < FloatOrd(::float_ord::core::f64::INFINITY));
|
||||
assert!(FloatOrd(-::float_ord::core::f32::INFINITY) < FloatOrd(::float_ord::core::f32::INFINITY));
|
||||
assert!(FloatOrd(::float_ord::core::f64::INFINITY) < FloatOrd(::float_ord::core::f64::NAN));
|
||||
assert!(FloatOrd(::float_ord::core::f32::INFINITY) < FloatOrd(::float_ord::core::f32::NAN));
|
||||
assert!(FloatOrd(-::float_ord::core::f64::NAN) < FloatOrd(::float_ord::core::f64::INFINITY));
|
||||
assert!(FloatOrd(-::float_ord::core::f32::NAN) < FloatOrd(::float_ord::core::f32::INFINITY));
|
||||
assert!(FloatOrd(crate::float_ord::core::f64::NAN) == FloatOrd(crate::float_ord::core::f64::NAN));
|
||||
assert!(FloatOrd(crate::float_ord::core::f32::NAN) == FloatOrd(crate::float_ord::core::f32::NAN));
|
||||
assert!(FloatOrd(-crate::float_ord::core::f64::NAN) < FloatOrd(crate::float_ord::core::f64::NAN));
|
||||
assert!(FloatOrd(-crate::float_ord::core::f32::NAN) < FloatOrd(crate::float_ord::core::f32::NAN));
|
||||
assert!(FloatOrd(-crate::float_ord::core::f64::INFINITY) < FloatOrd(crate::float_ord::core::f64::INFINITY));
|
||||
assert!(FloatOrd(-crate::float_ord::core::f32::INFINITY) < FloatOrd(crate::float_ord::core::f32::INFINITY));
|
||||
assert!(FloatOrd(crate::float_ord::core::f64::INFINITY) < FloatOrd(crate::float_ord::core::f64::NAN));
|
||||
assert!(FloatOrd(crate::float_ord::core::f32::INFINITY) < FloatOrd(crate::float_ord::core::f32::NAN));
|
||||
assert!(FloatOrd(-crate::float_ord::core::f64::NAN) < FloatOrd(crate::float_ord::core::f64::INFINITY));
|
||||
assert!(FloatOrd(-crate::float_ord::core::f32::NAN) < FloatOrd(crate::float_ord::core::f32::INFINITY));
|
||||
}
|
||||
|
||||
fn hash<F: Hash>(f: F) -> u64 {
|
||||
@ -123,15 +123,15 @@ mod tests {
|
||||
assert_ne!(hash(FloatOrd(0.0f32)), hash(FloatOrd(-0.0f32)));
|
||||
assert_eq!(hash(FloatOrd(-0.0f64)), hash(FloatOrd(-0.0f64)));
|
||||
assert_eq!(hash(FloatOrd(0.0f32)), hash(FloatOrd(0.0f32)));
|
||||
assert_ne!(hash(FloatOrd(::float_ord::core::f64::NAN)), hash(FloatOrd(-::float_ord::core::f64::NAN)));
|
||||
assert_ne!(hash(FloatOrd(::float_ord::core::f32::NAN)), hash(FloatOrd(-::float_ord::core::f32::NAN)));
|
||||
assert_eq!(hash(FloatOrd(::float_ord::core::f64::NAN)), hash(FloatOrd(::float_ord::core::f64::NAN)));
|
||||
assert_eq!(hash(FloatOrd(-::float_ord::core::f32::NAN)), hash(FloatOrd(-::float_ord::core::f32::NAN)));
|
||||
assert_ne!(hash(FloatOrd(crate::float_ord::core::f64::NAN)), hash(FloatOrd(-crate::float_ord::core::f64::NAN)));
|
||||
assert_ne!(hash(FloatOrd(crate::float_ord::core::f32::NAN)), hash(FloatOrd(-crate::float_ord::core::f32::NAN)));
|
||||
assert_eq!(hash(FloatOrd(crate::float_ord::core::f64::NAN)), hash(FloatOrd(crate::float_ord::core::f64::NAN)));
|
||||
assert_eq!(hash(FloatOrd(-crate::float_ord::core::f32::NAN)), hash(FloatOrd(-crate::float_ord::core::f32::NAN)));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_sort_nan() {
|
||||
let nan = ::float_ord::core::f64::NAN;
|
||||
let nan = crate::float_ord::core::f64::NAN;
|
||||
let mut v = [-1.0, 5.0, 0.0, -0.0, nan, 1.5, nan, 3.7];
|
||||
super::sort(&mut v);
|
||||
assert!(v[0] == -1.0);
|
||||
|
||||
@ -13,12 +13,12 @@ use std::time::Instant;
|
||||
use crate::main;
|
||||
use crate::state;
|
||||
use crate::state::Event;
|
||||
use ::logging;
|
||||
use ::util::c::into_cstring;
|
||||
use crate::logging;
|
||||
use crate::util::c::into_cstring;
|
||||
|
||||
// Traits
|
||||
use std::convert::TryFrom;
|
||||
use ::logging::Warn;
|
||||
use crate::logging::Warn;
|
||||
|
||||
|
||||
/// Gathers stuff defined in C or called by C
|
||||
|
||||
@ -1033,7 +1033,7 @@ mod procedures {
|
||||
mod test {
|
||||
use super::*;
|
||||
|
||||
use ::layout::test::*;
|
||||
use crate::layout::test::*;
|
||||
|
||||
/// Checks indexing of buttons
|
||||
#[test]
|
||||
|
||||
@ -112,7 +112,7 @@ pub enum Problem {
|
||||
// TODO: avoid, deprecate.
|
||||
// Handler instances should be long lived, not one per call.
|
||||
macro_rules! log_print {
|
||||
($level:expr, $($arg:tt)*) => (::logging::print($level, &format!($($arg)*)))
|
||||
($level:expr, $($arg:tt)*) => (crate::logging::print($level, &format!($($arg)*)))
|
||||
}
|
||||
|
||||
/// Approach 2
|
||||
|
||||
@ -215,7 +215,7 @@ mod c {
|
||||
use crate::state::visibility;
|
||||
use crate::util;
|
||||
|
||||
use logging::Warn;
|
||||
use crate::logging::Warn;
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C"
|
||||
|
||||
@ -11,7 +11,7 @@ use crate::main;
|
||||
use crate::util::DivCeil;
|
||||
|
||||
// traits
|
||||
use ::logging::Warn;
|
||||
use crate::logging::Warn;
|
||||
|
||||
/// Gathers stuff defined in C or called by C
|
||||
pub mod c {
|
||||
@ -20,7 +20,7 @@ pub mod c {
|
||||
use std::os::raw::{ c_char, c_void };
|
||||
use std::ptr;
|
||||
|
||||
use ::util::c::{COpaquePtr, Wrapped};
|
||||
use crate::util::c::{COpaquePtr, Wrapped};
|
||||
|
||||
// Defined in C
|
||||
|
||||
|
||||
@ -208,7 +208,7 @@ fn translate_layout_names(layouts: &Vec<LayoutId>) -> Vec<OwnedTranslation> {
|
||||
}
|
||||
|
||||
// Attempt to take all xkb names from gnome-desktop's xkb info.
|
||||
let xkb_translator = ::locale::XkbInfo::new();
|
||||
let xkb_translator = crate::locale::XkbInfo::new();
|
||||
|
||||
let translated_names = layouts.iter()
|
||||
.map(|id| match id {
|
||||
|
||||
@ -151,7 +151,7 @@ impl event_loop::Outcome for Outcome {
|
||||
|
||||
// Compare the old and new states as not to flood with updates,
|
||||
// which may look up in the file system.
|
||||
use animation::Outcome::*;
|
||||
use crate::animation::Outcome::*;
|
||||
let layout_selection = match &new_state.panel {
|
||||
Visible{ contents: new_contents, ..} => {
|
||||
let same
|
||||
|
||||
@ -19,10 +19,10 @@
|
||||
/*! CSS data loading. */
|
||||
|
||||
use std::env;
|
||||
use ::logging;
|
||||
use crate::logging;
|
||||
|
||||
use glib::prelude::ObjectExt;
|
||||
use logging::Warn;
|
||||
use crate::logging::Warn;
|
||||
|
||||
/// Gathers stuff defined in C or called by C
|
||||
pub mod c {
|
||||
|
||||
@ -21,14 +21,14 @@ use std::collections::HashSet;
|
||||
use std::ffi::CString;
|
||||
|
||||
use crate::vkeyboard::c::ZwpVirtualKeyboardV1;
|
||||
use ::action::Modifier;
|
||||
use ::imservice;
|
||||
use ::imservice::IMService;
|
||||
use ::keyboard::{ KeyCode, KeyStateId, Modifiers, PressType };
|
||||
use ::layout;
|
||||
use ::util::vec_remove;
|
||||
use ::vkeyboard;
|
||||
use ::vkeyboard::VirtualKeyboard;
|
||||
use crate::action::Modifier;
|
||||
use crate::imservice;
|
||||
use crate::imservice::IMService;
|
||||
use crate::keyboard::{ KeyCode, KeyStateId, Modifiers, PressType };
|
||||
use crate::layout;
|
||||
use crate::util::vec_remove;
|
||||
use crate::vkeyboard;
|
||||
use crate::vkeyboard::VirtualKeyboard;
|
||||
|
||||
// traits
|
||||
use std::iter::FromIterator;
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
/*! Testing functionality */
|
||||
|
||||
use ::data::parsing::Layout;
|
||||
use ::logging;
|
||||
use crate::data::parsing::Layout;
|
||||
use crate::logging;
|
||||
use xkbcommon::xkb;
|
||||
|
||||
|
||||
@ -9,7 +9,7 @@ pub struct CountAndPrint(u32);
|
||||
|
||||
impl logging::Handler for CountAndPrint {
|
||||
fn handle(&mut self, level: logging::Level, warning: &str) {
|
||||
use logging::Level::*;
|
||||
use crate::logging::Level::*;
|
||||
match level {
|
||||
Panic | Bug | Error | Warning | Surprise => {
|
||||
self.0 += 1;
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
/*! Assorted helpers */
|
||||
use std::rc::Rc;
|
||||
|
||||
use ::float_ord::FloatOrd;
|
||||
use crate::float_ord::FloatOrd;
|
||||
|
||||
use std::borrow::Borrow;
|
||||
use std::hash::{ Hash, Hasher };
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
/*! Managing the events belonging to virtual-keyboard interface. */
|
||||
|
||||
use ::keyboard::{ Modifiers, PressType };
|
||||
use ::submission::Timestamp;
|
||||
use crate::keyboard::{ Modifiers, PressType };
|
||||
use crate::submission::Timestamp;
|
||||
|
||||
/// Standard xkb keycode
|
||||
type KeyCode = u32;
|
||||
|
||||
Reference in New Issue
Block a user