Mode improvements for UI (#3109)
* `--mode=off` now works. * Add Mode::Off as a persistent CLI option. * "last" not "auto" as default. * Commit accidentally unsaved file. * Whitespace [ci:skip] * Mode CLI parse fix * or offline * Save mode when it gets changed. * Fix Offline mode * Fix up mode operations. * Make passive default, but not overriding. * Fix test * Maybe not everyone wants to run an archive node...
This commit is contained in:
@@ -78,7 +78,6 @@ pub struct ImportBlockchain {
|
||||
pub pruning_history: u64,
|
||||
pub compaction: DatabaseCompactionProfile,
|
||||
pub wal: bool,
|
||||
pub mode: Mode,
|
||||
pub tracing: Switch,
|
||||
pub fat_db: Switch,
|
||||
pub vm_type: VMType,
|
||||
@@ -97,7 +96,6 @@ pub struct ExportBlockchain {
|
||||
pub pruning_history: u64,
|
||||
pub compaction: DatabaseCompactionProfile,
|
||||
pub wal: bool,
|
||||
pub mode: Mode,
|
||||
pub fat_db: Switch,
|
||||
pub tracing: Switch,
|
||||
pub from_block: BlockID,
|
||||
@@ -155,7 +153,7 @@ fn execute_import(cmd: ImportBlockchain) -> Result<String, String> {
|
||||
try!(execute_upgrades(&db_dirs, algorithm, cmd.compaction.compaction_profile(db_dirs.fork_path().as_path())));
|
||||
|
||||
// prepare client config
|
||||
let client_config = to_client_config(&cmd.cache_config, cmd.mode, tracing, fat_db, cmd.compaction, cmd.wal, cmd.vm_type, "".into(), algorithm, cmd.pruning_history, cmd.check_seal);
|
||||
let client_config = to_client_config(&cmd.cache_config, Mode::Active, tracing, fat_db, cmd.compaction, cmd.wal, cmd.vm_type, "".into(), algorithm, cmd.pruning_history, cmd.check_seal);
|
||||
|
||||
// build client
|
||||
let service = try!(ClientService::start(
|
||||
@@ -303,7 +301,7 @@ fn execute_export(cmd: ExportBlockchain) -> Result<String, String> {
|
||||
try!(execute_upgrades(&db_dirs, algorithm, cmd.compaction.compaction_profile(db_dirs.fork_path().as_path())));
|
||||
|
||||
// prepare client config
|
||||
let client_config = to_client_config(&cmd.cache_config, cmd.mode, tracing, fat_db, cmd.compaction, cmd.wal, VMType::default(), "".into(), algorithm, cmd.pruning_history, cmd.check_seal);
|
||||
let client_config = to_client_config(&cmd.cache_config, Mode::Active, tracing, fat_db, cmd.compaction, cmd.wal, VMType::default(), "".into(), algorithm, cmd.pruning_history, cmd.check_seal);
|
||||
|
||||
let service = try!(ClientService::start(
|
||||
client_config,
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
[parity]
|
||||
mode = "active"
|
||||
mode = "last"
|
||||
mode_timeout = 300
|
||||
mode_alarm = 3600
|
||||
chain = "homestead"
|
||||
|
||||
@@ -74,7 +74,7 @@ usage! {
|
||||
}
|
||||
{
|
||||
// -- Operating Options
|
||||
flag_mode: String = "active", or |c: &Config| otry!(c.parity).mode.clone(),
|
||||
flag_mode: String = "last", or |c: &Config| otry!(c.parity).mode.clone(),
|
||||
flag_mode_timeout: u64 = 300u64, or |c: &Config| otry!(c.parity).mode_timeout.clone(),
|
||||
flag_mode_alarm: u64 = 3600u64, or |c: &Config| otry!(c.parity).mode_alarm.clone(),
|
||||
flag_chain: String = "homestead", or |c: &Config| otry!(c.parity).chain.clone(),
|
||||
@@ -104,8 +104,6 @@ usage! {
|
||||
flag_signer_no_validation: bool = false, or |_| None,
|
||||
|
||||
// -- Networking Options
|
||||
flag_no_network: bool = false,
|
||||
or |c: &Config| otry!(c.network).disable.clone(),
|
||||
flag_warp: bool = false,
|
||||
or |c: &Config| otry!(c.network).warp.clone(),
|
||||
flag_port: u16 = 30303u16,
|
||||
@@ -500,7 +498,7 @@ mod tests {
|
||||
arg_path: vec![],
|
||||
|
||||
// -- Operating Options
|
||||
flag_mode: "active".into(),
|
||||
flag_mode: "last".into(),
|
||||
flag_mode_timeout: 300u64,
|
||||
flag_mode_alarm: 3600u64,
|
||||
flag_chain: "xyz".into(),
|
||||
@@ -521,7 +519,6 @@ mod tests {
|
||||
flag_signer_no_validation: false,
|
||||
|
||||
// -- Networking Options
|
||||
flag_no_network: false,
|
||||
flag_warp: true,
|
||||
flag_port: 30303u16,
|
||||
flag_min_peers: 25u16,
|
||||
|
||||
@@ -18,11 +18,12 @@ Usage:
|
||||
|
||||
Operating Options:
|
||||
--mode MODE Set the operating mode. MODE can be one of:
|
||||
last - Uses the last-used mode, active if none.
|
||||
active - Parity continuously syncs the chain.
|
||||
passive - Parity syncs initially, then sleeps and
|
||||
wakes regularly to resync.
|
||||
dark - Parity syncs only when an external interface
|
||||
is active. (default: {flag_mode}).
|
||||
dark - Parity syncs only when the RPC is active.
|
||||
offline - Parity doesn't sync. (default: {flag_mode}).
|
||||
--mode-timeout SECS Specify the number of seconds before inactivity
|
||||
timeout occurs when mode is dark or passive
|
||||
(default: {flag_mode_timeout}).
|
||||
@@ -66,7 +67,6 @@ Account Options:
|
||||
development. (default: {flag_signer_no_validation})
|
||||
|
||||
Networking Options:
|
||||
--no-network Disable p2p networking. (default: {flag_no_network})
|
||||
--warp Enable syncing from the snapshot over the network. (default: {flag_warp})
|
||||
--port PORT Override the port on which the node should listen
|
||||
(default: {flag_port}).
|
||||
|
||||
@@ -23,7 +23,7 @@ use cli::{Args, ArgsError};
|
||||
use util::{Hashable, U256, Uint, Bytes, version_data, Secret, Address};
|
||||
use util::log::Colour;
|
||||
use ethsync::{NetworkConfiguration, is_valid_node_url, AllowIP};
|
||||
use ethcore::client::{VMType, Mode};
|
||||
use ethcore::client::VMType;
|
||||
use ethcore::miner::{MinerOptions, Banning};
|
||||
|
||||
use rpc::{IpcConfiguration, HttpConfiguration};
|
||||
@@ -80,7 +80,7 @@ impl Configuration {
|
||||
let pruning = try!(self.args.flag_pruning.parse());
|
||||
let pruning_history = self.args.flag_pruning_history;
|
||||
let vm_type = try!(self.vm_type());
|
||||
let mode = try!(to_mode(&self.args.flag_mode, self.args.flag_mode_timeout, self.args.flag_mode_alarm));
|
||||
let mode = match self.args.flag_mode.as_ref() { "last" => None, mode => Some(try!(to_mode(&mode, self.args.flag_mode_timeout, self.args.flag_mode_alarm))), };
|
||||
let miner_options = try!(self.miner_options());
|
||||
let logger_config = self.logger_config();
|
||||
let http_conf = try!(self.http_config());
|
||||
@@ -93,7 +93,6 @@ impl Configuration {
|
||||
let fat_db = try!(self.args.flag_fat_db.parse());
|
||||
let compaction = try!(self.args.flag_db_compaction.parse());
|
||||
let wal = !self.args.flag_fast_and_loose;
|
||||
let enable_network = self.enable_network(&mode);
|
||||
let warp_sync = self.args.flag_warp;
|
||||
let geth_compatibility = self.args.flag_geth;
|
||||
let signer_port = self.signer_port();
|
||||
@@ -156,7 +155,6 @@ impl Configuration {
|
||||
pruning_history: pruning_history,
|
||||
compaction: compaction,
|
||||
wal: wal,
|
||||
mode: mode,
|
||||
tracing: tracing,
|
||||
fat_db: fat_db,
|
||||
vm_type: vm_type,
|
||||
@@ -175,7 +173,6 @@ impl Configuration {
|
||||
pruning_history: pruning_history,
|
||||
compaction: compaction,
|
||||
wal: wal,
|
||||
mode: mode,
|
||||
tracing: tracing,
|
||||
fat_db: fat_db,
|
||||
from_block: try!(to_block_id(&self.args.flag_from)),
|
||||
@@ -190,7 +187,6 @@ impl Configuration {
|
||||
spec: spec,
|
||||
pruning: pruning,
|
||||
pruning_history: pruning_history,
|
||||
mode: mode,
|
||||
tracing: tracing,
|
||||
fat_db: fat_db,
|
||||
compaction: compaction,
|
||||
@@ -207,7 +203,6 @@ impl Configuration {
|
||||
spec: spec,
|
||||
pruning: pruning,
|
||||
pruning_history: pruning_history,
|
||||
mode: mode,
|
||||
tracing: tracing,
|
||||
fat_db: fat_db,
|
||||
compaction: compaction,
|
||||
@@ -246,7 +241,6 @@ impl Configuration {
|
||||
compaction: compaction,
|
||||
wal: wal,
|
||||
vm_type: vm_type,
|
||||
enable_network: enable_network,
|
||||
warp_sync: warp_sync,
|
||||
geth_compatibility: geth_compatibility,
|
||||
signer_port: signer_port,
|
||||
@@ -268,13 +262,6 @@ impl Configuration {
|
||||
})
|
||||
}
|
||||
|
||||
fn enable_network(&self, mode: &Mode) -> bool {
|
||||
match *mode {
|
||||
Mode::Dark(_) => false,
|
||||
_ => !self.args.flag_no_network,
|
||||
}
|
||||
}
|
||||
|
||||
fn vm_type(&self) -> Result<VMType, String> {
|
||||
if self.args.flag_jitvm {
|
||||
VMType::jit().ok_or("Parity is built without the JIT EVM.".into())
|
||||
@@ -767,7 +754,6 @@ mod tests {
|
||||
pruning_history: 64,
|
||||
compaction: Default::default(),
|
||||
wal: true,
|
||||
mode: Default::default(),
|
||||
tracing: Default::default(),
|
||||
fat_db: Default::default(),
|
||||
vm_type: VMType::Interpreter,
|
||||
@@ -790,7 +776,6 @@ mod tests {
|
||||
format: Default::default(),
|
||||
compaction: Default::default(),
|
||||
wal: true,
|
||||
mode: Default::default(),
|
||||
tracing: Default::default(),
|
||||
fat_db: Default::default(),
|
||||
from_block: BlockID::Number(1),
|
||||
@@ -813,7 +798,6 @@ mod tests {
|
||||
format: Some(DataFormat::Hex),
|
||||
compaction: Default::default(),
|
||||
wal: true,
|
||||
mode: Default::default(),
|
||||
tracing: Default::default(),
|
||||
fat_db: Default::default(),
|
||||
from_block: BlockID::Number(1),
|
||||
@@ -858,7 +842,6 @@ mod tests {
|
||||
compaction: Default::default(),
|
||||
wal: true,
|
||||
vm_type: Default::default(),
|
||||
enable_network: true,
|
||||
geth_compatibility: false,
|
||||
signer_port: Some(8180),
|
||||
net_settings: Default::default(),
|
||||
|
||||
@@ -46,7 +46,7 @@ fn to_seconds(s: &str) -> Result<u64, String> {
|
||||
"hourly" | "1hour" | "1 hour" | "hour" => Ok(60 * 60),
|
||||
"daily" | "1day" | "1 day" | "day" => Ok(24 * 60 * 60),
|
||||
x if x.ends_with("seconds") => x[0..x.len() - 7].parse().map_err(bad),
|
||||
x if x.ends_with("minutes") => x[0..x.len() -7].parse::<u64>().map_err(bad).map(|x| x * 60),
|
||||
x if x.ends_with("minutes") => x[0..x.len() - 7].parse::<u64>().map_err(bad).map(|x| x * 60),
|
||||
x if x.ends_with("hours") => x[0..x.len() - 5].parse::<u64>().map_err(bad).map(|x| x * 60 * 60),
|
||||
x if x.ends_with("days") => x[0..x.len() - 4].parse::<u64>().map_err(bad).map(|x| x * 24 * 60 * 60),
|
||||
x => x.parse().map_err(bad),
|
||||
@@ -58,7 +58,8 @@ pub fn to_mode(s: &str, timeout: u64, alarm: u64) -> Result<Mode, String> {
|
||||
"active" => Ok(Mode::Active),
|
||||
"passive" => Ok(Mode::Passive(Duration::from_secs(timeout), Duration::from_secs(alarm))),
|
||||
"dark" => Ok(Mode::Dark(Duration::from_secs(timeout))),
|
||||
_ => Err(format!("{}: Invalid address for --mode. Must be one of active, passive or dark.", s)),
|
||||
"offline" => Ok(Mode::Off),
|
||||
_ => Err(format!("{}: Invalid value for --mode. Must be one of active, passive, dark or offline.", s)),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -20,6 +20,7 @@ use util::{Address, U256, version_data};
|
||||
use util::journaldb::Algorithm;
|
||||
use ethcore::spec::Spec;
|
||||
use ethcore::ethereum;
|
||||
use ethcore::client::Mode;
|
||||
use ethcore::miner::{GasPricer, GasPriceCalibratorOptions};
|
||||
use user_defaults::UserDefaults;
|
||||
|
||||
@@ -264,6 +265,10 @@ pub fn fatdb_switch_to_bool(switch: Switch, user_defaults: &UserDefaults, algori
|
||||
result
|
||||
}
|
||||
|
||||
pub fn mode_switch_to_bool(switch: Option<Mode>, user_defaults: &UserDefaults) -> Result<Mode, String> {
|
||||
Ok(switch.unwrap_or(user_defaults.mode.clone()))
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use util::journaldb::Algorithm;
|
||||
|
||||
@@ -37,7 +37,7 @@ use dapps::WebappServer;
|
||||
use io_handler::ClientIoHandler;
|
||||
use params::{
|
||||
SpecType, Pruning, AccountsConfig, GasPricerConfig, MinerExtras, Switch,
|
||||
tracing_switch_to_bool, fatdb_switch_to_bool,
|
||||
tracing_switch_to_bool, fatdb_switch_to_bool, mode_switch_to_bool
|
||||
};
|
||||
use helpers::{to_client_config, execute_upgrades, passwords_from_files};
|
||||
use dir::Directories;
|
||||
@@ -75,13 +75,12 @@ pub struct RunCmd {
|
||||
pub acc_conf: AccountsConfig,
|
||||
pub gas_pricer: GasPricerConfig,
|
||||
pub miner_extras: MinerExtras,
|
||||
pub mode: Mode,
|
||||
pub mode: Option<Mode>,
|
||||
pub tracing: Switch,
|
||||
pub fat_db: Switch,
|
||||
pub compaction: DatabaseCompactionProfile,
|
||||
pub wal: bool,
|
||||
pub vm_type: VMType,
|
||||
pub enable_network: bool,
|
||||
pub geth_compatibility: bool,
|
||||
pub signer_port: Option<u16>,
|
||||
pub net_settings: NetworkSettings,
|
||||
@@ -137,6 +136,11 @@ pub fn execute(cmd: RunCmd, logger: Arc<RotatingLogger>) -> Result<(), String> {
|
||||
// check if fatdb is on
|
||||
let fat_db = try!(fatdb_switch_to_bool(cmd.fat_db, &user_defaults, algorithm));
|
||||
|
||||
// get the mode
|
||||
let mode = try!(mode_switch_to_bool(cmd.mode, &user_defaults));
|
||||
trace!(target: "mode", "mode is {:?}", mode);
|
||||
let network_enabled = match &mode { &Mode::Dark(_) | &Mode::Off => false, _ => true, };
|
||||
|
||||
// prepare client and snapshot paths.
|
||||
let client_path = db_dirs.client_path(algorithm);
|
||||
let snapshot_path = db_dirs.snapshot_path();
|
||||
@@ -162,6 +166,7 @@ pub fn execute(cmd: RunCmd, logger: Arc<RotatingLogger>) -> Result<(), String> {
|
||||
false => "".to_owned(),
|
||||
}
|
||||
);
|
||||
info!("Operating mode: {}", Colour::White.bold().paint(format!("{}", mode)));
|
||||
|
||||
// display warning about using experimental journaldb alorithm
|
||||
if !algorithm.is_stable() {
|
||||
@@ -196,7 +201,7 @@ pub fn execute(cmd: RunCmd, logger: Arc<RotatingLogger>) -> Result<(), String> {
|
||||
// create client config
|
||||
let client_config = to_client_config(
|
||||
&cmd.cache_config,
|
||||
cmd.mode,
|
||||
mode,
|
||||
tracing,
|
||||
fat_db,
|
||||
cmd.compaction,
|
||||
@@ -248,7 +253,7 @@ pub fn execute(cmd: RunCmd, logger: Arc<RotatingLogger>) -> Result<(), String> {
|
||||
service.add_notify(chain_notify.clone());
|
||||
|
||||
// start network
|
||||
if cmd.enable_network {
|
||||
if network_enabled {
|
||||
chain_notify.start();
|
||||
}
|
||||
|
||||
@@ -321,6 +326,19 @@ pub fn execute(cmd: RunCmd, logger: Arc<RotatingLogger>) -> Result<(), String> {
|
||||
});
|
||||
service.register_io_handler(io_handler.clone()).expect("Error registering IO handler");
|
||||
|
||||
// save user defaults
|
||||
user_defaults.pruning = algorithm;
|
||||
user_defaults.tracing = tracing;
|
||||
try!(user_defaults.save(&user_defaults_path));
|
||||
|
||||
let on_mode_change = move |mode: &Mode| {
|
||||
user_defaults.mode = mode.clone();
|
||||
let _ = user_defaults.save(&user_defaults_path); // discard failures - there's nothing we can do
|
||||
};
|
||||
|
||||
// tell client how to save the default mode if it gets changed.
|
||||
client.on_mode_change(on_mode_change);
|
||||
|
||||
// the watcher must be kept alive.
|
||||
let _watcher = match cmd.no_periodic_snapshot {
|
||||
true => None,
|
||||
@@ -347,11 +365,6 @@ pub fn execute(cmd: RunCmd, logger: Arc<RotatingLogger>) -> Result<(), String> {
|
||||
url::open(&format!("http://{}:{}/", cmd.dapps_conf.interface, cmd.dapps_conf.port));
|
||||
}
|
||||
|
||||
// save user defaults
|
||||
user_defaults.pruning = algorithm;
|
||||
user_defaults.tracing = tracing;
|
||||
try!(user_defaults.save(&user_defaults_path));
|
||||
|
||||
// Handle exit
|
||||
wait_for_exit(panic_handler, http_server, ipc_server, dapps_server, signer_server);
|
||||
|
||||
|
||||
@@ -54,7 +54,6 @@ pub struct SnapshotCommand {
|
||||
pub spec: SpecType,
|
||||
pub pruning: Pruning,
|
||||
pub pruning_history: u64,
|
||||
pub mode: Mode,
|
||||
pub tracing: Switch,
|
||||
pub fat_db: Switch,
|
||||
pub compaction: DatabaseCompactionProfile,
|
||||
@@ -158,7 +157,7 @@ impl SnapshotCommand {
|
||||
try!(execute_upgrades(&db_dirs, algorithm, self.compaction.compaction_profile(db_dirs.fork_path().as_path())));
|
||||
|
||||
// prepare client config
|
||||
let client_config = to_client_config(&self.cache_config, self.mode, tracing, fat_db, self.compaction, self.wal, VMType::default(), "".into(), algorithm, self.pruning_history, true);
|
||||
let client_config = to_client_config(&self.cache_config, Mode::Active, tracing, fat_db, self.compaction, self.wal, VMType::default(), "".into(), algorithm, self.pruning_history, true);
|
||||
|
||||
let service = try!(ClientService::start(
|
||||
client_config,
|
||||
|
||||
@@ -18,6 +18,7 @@ use std::fs::File;
|
||||
use std::io::Write;
|
||||
use std::path::Path;
|
||||
use std::collections::BTreeMap;
|
||||
use std::time::Duration;
|
||||
use serde::{Serialize, Serializer, Error, Deserialize, Deserializer};
|
||||
use serde::de::{Visitor, MapVisitor};
|
||||
use serde::de::impls::BTreeMapVisitor;
|
||||
@@ -25,12 +26,14 @@ use serde_json::Value;
|
||||
use serde_json::de::from_reader;
|
||||
use serde_json::ser::to_string;
|
||||
use util::journaldb::Algorithm;
|
||||
use ethcore::client::Mode;
|
||||
|
||||
pub struct UserDefaults {
|
||||
pub is_first_launch: bool,
|
||||
pub pruning: Algorithm,
|
||||
pub tracing: bool,
|
||||
pub fat_db: bool,
|
||||
pub mode: Mode,
|
||||
}
|
||||
|
||||
impl Serialize for UserDefaults {
|
||||
@@ -40,6 +43,21 @@ impl Serialize for UserDefaults {
|
||||
map.insert("pruning".into(), Value::String(self.pruning.as_str().into()));
|
||||
map.insert("tracing".into(), Value::Bool(self.tracing));
|
||||
map.insert("fat_db".into(), Value::Bool(self.fat_db));
|
||||
let mode_str = match self.mode {
|
||||
Mode::Off => "offline",
|
||||
Mode::Dark(timeout) => {
|
||||
map.insert("mode.timeout".into(), Value::U64(timeout.as_secs()));
|
||||
"dark"
|
||||
},
|
||||
Mode::Passive(timeout, alarm) => {
|
||||
map.insert("mode.timeout".into(), Value::U64(timeout.as_secs()));
|
||||
map.insert("mode.alarm".into(), Value::U64(alarm.as_secs()));
|
||||
"passive"
|
||||
},
|
||||
Mode::Active => "active",
|
||||
};
|
||||
map.insert("mode".into(), Value::String(mode_str.into()));
|
||||
|
||||
map.serialize(serializer)
|
||||
}
|
||||
}
|
||||
@@ -67,11 +85,28 @@ impl Visitor for UserDefaultsVisitor {
|
||||
let fat_db: Value = map.remove("fat_db".into()).unwrap_or_else(|| Value::Bool(false));
|
||||
let fat_db = try!(fat_db.as_bool().ok_or_else(|| Error::custom("invalid fat_db value")));
|
||||
|
||||
let mode: Value = map.remove("mode".into()).unwrap_or_else(|| Value::String("active".to_owned()));
|
||||
let mode = match try!(mode.as_str().ok_or_else(|| Error::custom("invalid mode value"))) {
|
||||
"offline" => Mode::Off,
|
||||
"dark" => {
|
||||
let timeout = try!(map.remove("mode.timeout".into()).and_then(|v| v.as_u64()).ok_or_else(|| Error::custom("invalid/missing mode.timeout value")));
|
||||
Mode::Dark(Duration::from_secs(timeout))
|
||||
},
|
||||
"passive" => {
|
||||
let timeout = try!(map.remove("mode.timeout".into()).and_then(|v| v.as_u64()).ok_or_else(|| Error::custom("invalid/missing mode.timeout value")));
|
||||
let alarm = try!(map.remove("mode.alarm".into()).and_then(|v| v.as_u64()).ok_or_else(|| Error::custom("invalid/missing mode.alarm value")));
|
||||
Mode::Passive(Duration::from_secs(timeout), Duration::from_secs(alarm))
|
||||
},
|
||||
"active" => Mode::Active,
|
||||
_ => { return Err(Error::custom("invalid mode value")); },
|
||||
};
|
||||
|
||||
let user_defaults = UserDefaults {
|
||||
is_first_launch: false,
|
||||
pruning: pruning,
|
||||
tracing: tracing,
|
||||
fat_db: fat_db,
|
||||
mode: mode,
|
||||
};
|
||||
|
||||
Ok(user_defaults)
|
||||
@@ -85,6 +120,7 @@ impl Default for UserDefaults {
|
||||
pruning: Algorithm::default(),
|
||||
tracing: false,
|
||||
fat_db: false,
|
||||
mode: Mode::Active,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -97,7 +133,7 @@ impl UserDefaults {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn save<P>(self, path: P) -> Result<(), String> where P: AsRef<Path> {
|
||||
pub fn save<P>(&self, path: P) -> Result<(), String> where P: AsRef<Path> {
|
||||
let mut file: File = try!(File::create(path).map_err(|_| "Cannot create user defaults file".to_owned()));
|
||||
file.write_all(to_string(&self).unwrap().as_bytes()).map_err(|_| "Failed to save user defaults".to_owned())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user