rust: Use 2018 eition

This edition has better syntax around scoping and `use`.
This commit is contained in:
Dorota Czaplejewicz
2022-12-21 12:17:22 +00:00
parent 38165ac039
commit 828279d03c
18 changed files with 78 additions and 77 deletions

View File

@ -1,6 +1,7 @@
[package] [package]
name = "rs" name = "rs"
version = "0.1.0" version = "0.1.0"
edition = "2018"
[lib] [lib]
name = "rs" name = "rs"

View File

@ -192,7 +192,7 @@ fn iter_layout_sources(
} }
fn load_layout_data(source: DataSource) fn load_layout_data(source: DataSource)
-> Result<::layout::LayoutParseData, LoadError> -> Result<crate::layout::LayoutParseData, LoadError>
{ {
let handler = logging::Print {}; let handler = logging::Print {};
match source { match source {
@ -268,7 +268,7 @@ pub fn load_layout(
mod tests { mod tests {
use super::*; use super::*;
use ::logging::ProblemPanic; use crate::logging::ProblemPanic;
#[test] #[test]
fn parsing_fallback() { fn parsing_fallback() {

View File

@ -10,7 +10,7 @@ pub mod parsing;
use std::io; use std::io;
use std::fmt; use std::fmt;
use ::keyboard::FormattingError; use crate::keyboard::FormattingError;
/// Errors encountered loading the layout into yaml /// Errors encountered loading the layout into yaml
#[derive(Debug)] #[derive(Debug)]

View File

@ -14,19 +14,19 @@ use xkbcommon::xkb;
use super::{ Error, LoadError }; use super::{ Error, LoadError };
use ::action; use crate::action;
use crate::keyboard::{ use crate::keyboard::{
Key, generate_keymaps, generate_keycodes, KeyCode, FormattingError Key, generate_keymaps, generate_keycodes, KeyCode, FormattingError
}; };
use ::layout; use crate::layout;
use ::logging; use crate::logging;
use ::resources; use crate::resources;
// traits, derives // traits, derives
use serde::Deserialize; use serde::Deserialize;
use std::io::BufReader; use std::io::BufReader;
use std::iter::FromIterator; 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 // 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) 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() let button_names = self.views.values()
.flat_map(|rows| { .flat_map(|rows| {
@ -164,7 +164,7 @@ impl Layout {
let button_names: HashSet<&str> let button_names: HashSet<&str>
= HashSet::from_iter(button_names); = 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| {( = button_names.iter().map(|name| {(
*name, *name,
create_action( create_action(
@ -182,7 +182,7 @@ impl Layout {
let button_states = HashMap::<String, Key>::from_iter( let button_states = HashMap::<String, Key>::from_iter(
button_actions.into_iter().map(|(name, action)| { button_actions.into_iter().map(|(name, action)| {
let keycodes = match &action { let keycodes = match &action {
::action::Action::Submit { text: _, keys } => { crate::action::Action::Submit { text: _, keys } => {
keys.iter().map(|named_keysym| { keys.iter().map(|named_keysym| {
symbolmap.get(named_keysym.0.as_str()) symbolmap.get(named_keysym.0.as_str())
.expect( .expect(
@ -292,7 +292,7 @@ fn create_action<H: logging::Handler>(
name: &str, name: &str,
view_names: Vec<&String>, view_names: Vec<&String>,
warning_handler: &mut H, warning_handler: &mut H,
) -> ::action::Action { ) -> crate::action::Action {
let default_meta = ButtonMeta::default(); let default_meta = ButtonMeta::default();
let symbol_meta = button_info.get(name) let symbol_meta = button_info.get(name)
.unwrap_or(&default_meta); .unwrap_or(&default_meta);
@ -356,7 +356,7 @@ fn create_action<H: logging::Handler>(
match submission { match submission {
SubmitData::Action( SubmitData::Action(
Action::SetView(view_name) Action::SetView(view_name)
) => ::action::Action::SetView( ) => crate::action::Action::SetView(
filter_view_name( filter_view_name(
name, view_name.clone(), &view_names, name, view_name.clone(), &view_names,
warning_handler, warning_handler,
@ -366,7 +366,7 @@ fn create_action<H: logging::Handler>(
lock_view, unlock_view, lock_view, unlock_view,
pops, pops,
looks_locked_from, looks_locked_from,
}) => ::action::Action::LockView { }) => crate::action::Action::LockView {
lock: filter_view_name( lock: filter_view_name(
name, name,
lock_view.clone(), lock_view.clone(),
@ -384,11 +384,11 @@ fn create_action<H: logging::Handler>(
}, },
SubmitData::Action( SubmitData::Action(
Action::ShowPrefs Action::ShowPrefs
) => ::action::Action::ShowPreferences, ) => crate::action::Action::ShowPreferences,
SubmitData::Action(Action::Erase) => action::Action::Erase, SubmitData::Action(Action::Erase) => action::Action::Erase,
SubmitData::Keysym(keysym) => ::action::Action::Submit { SubmitData::Keysym(keysym) => crate::action::Action::Submit {
text: None, text: None,
keys: vec!(::action::KeySym( keys: vec!(crate::action::KeySym(
match keysym_valid(keysym.as_str()) { match keysym_valid(keysym.as_str()) {
true => keysym.clone(), true => keysym.clone(),
false => { 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( text: CString::new(text.clone()).or_warn(
warning_handler, warning_handler,
logging::Problem::Warning, logging::Problem::Warning,
@ -412,7 +412,7 @@ fn create_action<H: logging::Handler>(
), ),
keys: text.chars().map(|codepoint| { keys: text.chars().map(|codepoint| {
let codepoint_string = codepoint.to_string(); 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, true => codepoint_string,
false => format!("U{:04X}", codepoint as u32), false => format!("U{:04X}", codepoint as u32),
}) })
@ -452,7 +452,7 @@ fn create_button<H: logging::Handler>(
name: &str, name: &str,
data: Key, data: Key,
warning_handler: &mut H, warning_handler: &mut H,
) -> ::layout::Button { ) -> crate::layout::Button {
let cname = CString::new(name.clone()) let cname = CString::new(name.clone())
.expect("Bad name"); .expect("Bad name");
// don't remove, because multiple buttons with the same name are allowed // 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 // TODO: move conversion to the C/Rust boundary
let label = if let Some(label) = &button_meta.label { 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")) .expect("Bad label"))
} else if let Some(icon) = &button_meta.icon { } 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")) .expect("Bad icon"))
} else if let Some(text) = &button_meta.text { } else if let Some(text) = &button_meta.text {
::layout::Label::Text( crate::layout::Label::Text(
CString::new(text.as_str()) CString::new(text.as_str())
.or_warn( .or_warn(
warning_handler, warning_handler,
@ -477,7 +477,7 @@ fn create_button<H: logging::Handler>(
).unwrap_or_else(|| CString::new("").unwrap()) ).unwrap_or_else(|| CString::new("").unwrap())
) )
} else { } else {
::layout::Label::Text(cname.clone()) crate::layout::Label::Text(cname.clone())
}; };
let outline_name = match &button_meta.outline { let outline_name = match &button_meta.outline {
@ -541,7 +541,7 @@ mod tests {
use std::env; use std::env;
use ::logging::ProblemPanic; use crate::logging::ProblemPanic;
fn path_from_root(file: &'static str) -> PathBuf { fn path_from_root(file: &'static str) -> PathBuf {
let source_dir = env::var("SOURCE_DIR") let source_dir = env::var("SOURCE_DIR")
@ -637,7 +637,7 @@ mod tests {
.get_rows()[0].1 .get_rows()[0].1
.get_buttons()[0].1 .get_buttons()[0].1
.label, .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_rows()[0].1
.get_buttons()[0].1 .get_buttons()[0].1
.label, .label,
::layout::Label::Text(CString::new("test").unwrap()) crate::layout::Label::Text(CString::new("test").unwrap())
); );
} }
@ -717,9 +717,9 @@ mod tests {
Vec::new(), Vec::new(),
&mut ProblemPanic, &mut ProblemPanic,
), ),
::action::Action::Submit { crate::action::Action::Submit {
text: Some(CString::new(".").unwrap()), text: Some(CString::new(".").unwrap()),
keys: vec!(::action::KeySym("U002E".into())), keys: vec!(crate::action::KeySym("U002E".into())),
}, },
); );
} }

View File

@ -2,11 +2,11 @@
use cairo; use cairo;
use ::action::{ Action, Modifier }; use crate::action::{ Action, Modifier };
use ::keyboard; use crate::keyboard;
use crate::layout::{ Button, ButtonPosition, Label, LatchedState, Layout }; use crate::layout::{ Button, ButtonPosition, Label, LatchedState, Layout };
use ::layout::c::{ Bounds, EekGtkKeyboard, Point }; use crate::layout::c::{ Bounds, EekGtkKeyboard, Point };
use ::submission::c::Submission as CSubmission; use crate::submission::c::Submission as CSubmission;
use glib::translate::FromGlibPtrNone; use glib::translate::FromGlibPtrNone;
use gtk::prelude::WidgetExt; use gtk::prelude::WidgetExt;

View File

@ -13,9 +13,9 @@
extern crate core; extern crate core;
use ::float_ord::core::cmp::{Eq, Ord, Ordering, PartialEq, PartialOrd}; use crate::float_ord::core::cmp::{Eq, Ord, Ordering, PartialEq, PartialOrd};
use ::float_ord::core::hash::{Hash, Hasher}; use crate::float_ord::core::hash::{Hash, Hasher};
use ::float_ord::core::mem::transmute; use crate::float_ord::core::mem::transmute;
/// A wrapper for floats, that implements total equality and ordering /// A wrapper for floats, that implements total equality and ordering
/// and hashing. /// and hashing.
@ -99,16 +99,16 @@ mod tests {
assert!(FloatOrd(1.0f32) == FloatOrd(1.0f32)); assert!(FloatOrd(1.0f32) == FloatOrd(1.0f32));
assert!(FloatOrd(0.0f64) > FloatOrd(-0.0f64)); assert!(FloatOrd(0.0f64) > FloatOrd(-0.0f64));
assert!(FloatOrd(0.0f32) > FloatOrd(-0.0f32)); assert!(FloatOrd(0.0f32) > FloatOrd(-0.0f32));
assert!(FloatOrd(::float_ord::core::f64::NAN) == FloatOrd(::float_ord::core::f64::NAN)); assert!(FloatOrd(crate::float_ord::core::f64::NAN) == FloatOrd(crate::float_ord::core::f64::NAN));
assert!(FloatOrd(::float_ord::core::f32::NAN) == FloatOrd(::float_ord::core::f32::NAN)); assert!(FloatOrd(crate::float_ord::core::f32::NAN) == FloatOrd(crate::float_ord::core::f32::NAN));
assert!(FloatOrd(-::float_ord::core::f64::NAN) < FloatOrd(::float_ord::core::f64::NAN)); assert!(FloatOrd(-crate::float_ord::core::f64::NAN) < FloatOrd(crate::float_ord::core::f64::NAN));
assert!(FloatOrd(-::float_ord::core::f32::NAN) < FloatOrd(::float_ord::core::f32::NAN)); assert!(FloatOrd(-crate::float_ord::core::f32::NAN) < FloatOrd(crate::float_ord::core::f32::NAN));
assert!(FloatOrd(-::float_ord::core::f64::INFINITY) < FloatOrd(::float_ord::core::f64::INFINITY)); assert!(FloatOrd(-crate::float_ord::core::f64::INFINITY) < FloatOrd(crate::float_ord::core::f64::INFINITY));
assert!(FloatOrd(-::float_ord::core::f32::INFINITY) < FloatOrd(::float_ord::core::f32::INFINITY)); assert!(FloatOrd(-crate::float_ord::core::f32::INFINITY) < FloatOrd(crate::float_ord::core::f32::INFINITY));
assert!(FloatOrd(::float_ord::core::f64::INFINITY) < FloatOrd(::float_ord::core::f64::NAN)); assert!(FloatOrd(crate::float_ord::core::f64::INFINITY) < FloatOrd(crate::float_ord::core::f64::NAN));
assert!(FloatOrd(::float_ord::core::f32::INFINITY) < FloatOrd(::float_ord::core::f32::NAN)); assert!(FloatOrd(crate::float_ord::core::f32::INFINITY) < FloatOrd(crate::float_ord::core::f32::NAN));
assert!(FloatOrd(-::float_ord::core::f64::NAN) < FloatOrd(::float_ord::core::f64::INFINITY)); assert!(FloatOrd(-crate::float_ord::core::f64::NAN) < FloatOrd(crate::float_ord::core::f64::INFINITY));
assert!(FloatOrd(-::float_ord::core::f32::NAN) < FloatOrd(::float_ord::core::f32::INFINITY)); assert!(FloatOrd(-crate::float_ord::core::f32::NAN) < FloatOrd(crate::float_ord::core::f32::INFINITY));
} }
fn hash<F: Hash>(f: F) -> u64 { fn hash<F: Hash>(f: F) -> u64 {
@ -123,15 +123,15 @@ mod tests {
assert_ne!(hash(FloatOrd(0.0f32)), hash(FloatOrd(-0.0f32))); 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.0f64)), hash(FloatOrd(-0.0f64)));
assert_eq!(hash(FloatOrd(0.0f32)), hash(FloatOrd(0.0f32))); 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(crate::float_ord::core::f64::NAN)), hash(FloatOrd(-crate::float_ord::core::f64::NAN)));
assert_ne!(hash(FloatOrd(::float_ord::core::f32::NAN)), hash(FloatOrd(-::float_ord::core::f32::NAN))); assert_ne!(hash(FloatOrd(crate::float_ord::core::f32::NAN)), hash(FloatOrd(-crate::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(crate::float_ord::core::f64::NAN)), hash(FloatOrd(crate::float_ord::core::f64::NAN)));
assert_eq!(hash(FloatOrd(-::float_ord::core::f32::NAN)), hash(FloatOrd(-::float_ord::core::f32::NAN))); assert_eq!(hash(FloatOrd(-crate::float_ord::core::f32::NAN)), hash(FloatOrd(-crate::float_ord::core::f32::NAN)));
} }
#[test] #[test]
fn test_sort_nan() { 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]; let mut v = [-1.0, 5.0, 0.0, -0.0, nan, 1.5, nan, 3.7];
super::sort(&mut v); super::sort(&mut v);
assert!(v[0] == -1.0); assert!(v[0] == -1.0);

View File

@ -13,12 +13,12 @@ use std::time::Instant;
use crate::main; use crate::main;
use crate::state; use crate::state;
use crate::state::Event; use crate::state::Event;
use ::logging; use crate::logging;
use ::util::c::into_cstring; use crate::util::c::into_cstring;
// Traits // Traits
use std::convert::TryFrom; use std::convert::TryFrom;
use ::logging::Warn; use crate::logging::Warn;
/// Gathers stuff defined in C or called by C /// Gathers stuff defined in C or called by C

View File

@ -1033,7 +1033,7 @@ mod procedures {
mod test { mod test {
use super::*; use super::*;
use ::layout::test::*; use crate::layout::test::*;
/// Checks indexing of buttons /// Checks indexing of buttons
#[test] #[test]

View File

@ -112,7 +112,7 @@ pub enum Problem {
// TODO: avoid, deprecate. // TODO: avoid, deprecate.
// Handler instances should be long lived, not one per call. // Handler instances should be long lived, not one per call.
macro_rules! log_print { 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 /// Approach 2

View File

@ -215,7 +215,7 @@ mod c {
use crate::state::visibility; use crate::state::visibility;
use crate::util; use crate::util;
use logging::Warn; use crate::logging::Warn;
#[no_mangle] #[no_mangle]
pub extern "C" pub extern "C"

View File

@ -11,7 +11,7 @@ use crate::main;
use crate::util::DivCeil; use crate::util::DivCeil;
// traits // traits
use ::logging::Warn; use crate::logging::Warn;
/// Gathers stuff defined in C or called by C /// Gathers stuff defined in C or called by C
pub mod c { pub mod c {
@ -20,7 +20,7 @@ pub mod c {
use std::os::raw::{ c_char, c_void }; use std::os::raw::{ c_char, c_void };
use std::ptr; use std::ptr;
use ::util::c::{COpaquePtr, Wrapped}; use crate::util::c::{COpaquePtr, Wrapped};
// Defined in C // Defined in C

View File

@ -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. // 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() let translated_names = layouts.iter()
.map(|id| match id { .map(|id| match id {

View File

@ -151,7 +151,7 @@ impl event_loop::Outcome for Outcome {
// Compare the old and new states as not to flood with updates, // Compare the old and new states as not to flood with updates,
// which may look up in the file system. // which may look up in the file system.
use animation::Outcome::*; use crate::animation::Outcome::*;
let layout_selection = match &new_state.panel { let layout_selection = match &new_state.panel {
Visible{ contents: new_contents, ..} => { Visible{ contents: new_contents, ..} => {
let same let same

View File

@ -19,10 +19,10 @@
/*! CSS data loading. */ /*! CSS data loading. */
use std::env; use std::env;
use ::logging; use crate::logging;
use glib::prelude::ObjectExt; use glib::prelude::ObjectExt;
use logging::Warn; use crate::logging::Warn;
/// Gathers stuff defined in C or called by C /// Gathers stuff defined in C or called by C
pub mod c { pub mod c {

View File

@ -21,14 +21,14 @@ use std::collections::HashSet;
use std::ffi::CString; use std::ffi::CString;
use crate::vkeyboard::c::ZwpVirtualKeyboardV1; use crate::vkeyboard::c::ZwpVirtualKeyboardV1;
use ::action::Modifier; use crate::action::Modifier;
use ::imservice; use crate::imservice;
use ::imservice::IMService; use crate::imservice::IMService;
use ::keyboard::{ KeyCode, KeyStateId, Modifiers, PressType }; use crate::keyboard::{ KeyCode, KeyStateId, Modifiers, PressType };
use ::layout; use crate::layout;
use ::util::vec_remove; use crate::util::vec_remove;
use ::vkeyboard; use crate::vkeyboard;
use ::vkeyboard::VirtualKeyboard; use crate::vkeyboard::VirtualKeyboard;
// traits // traits
use std::iter::FromIterator; use std::iter::FromIterator;

View File

@ -1,7 +1,7 @@
/*! Testing functionality */ /*! Testing functionality */
use ::data::parsing::Layout; use crate::data::parsing::Layout;
use ::logging; use crate::logging;
use xkbcommon::xkb; use xkbcommon::xkb;
@ -9,7 +9,7 @@ pub struct CountAndPrint(u32);
impl logging::Handler for CountAndPrint { impl logging::Handler for CountAndPrint {
fn handle(&mut self, level: logging::Level, warning: &str) { fn handle(&mut self, level: logging::Level, warning: &str) {
use logging::Level::*; use crate::logging::Level::*;
match level { match level {
Panic | Bug | Error | Warning | Surprise => { Panic | Bug | Error | Warning | Surprise => {
self.0 += 1; self.0 += 1;

View File

@ -1,7 +1,7 @@
/*! Assorted helpers */ /*! Assorted helpers */
use std::rc::Rc; use std::rc::Rc;
use ::float_ord::FloatOrd; use crate::float_ord::FloatOrd;
use std::borrow::Borrow; use std::borrow::Borrow;
use std::hash::{ Hash, Hasher }; use std::hash::{ Hash, Hasher };

View File

@ -1,7 +1,7 @@
/*! Managing the events belonging to virtual-keyboard interface. */ /*! Managing the events belonging to virtual-keyboard interface. */
use ::keyboard::{ Modifiers, PressType }; use crate::keyboard::{ Modifiers, PressType };
use ::submission::Timestamp; use crate::submission::Timestamp;
/// Standard xkb keycode /// Standard xkb keycode
type KeyCode = u32; type KeyCode = u32;