|
|
@ -1,8 +1,8 @@ |
|
|
|
use crate::data::AppData; |
|
|
|
use crate::data::AppData; |
|
|
|
use crate::Result; |
|
|
|
use crate::Result; |
|
|
|
use std::io::{Read, Write, BufWriter}; |
|
|
|
|
|
|
|
use std::path::Path; |
|
|
|
|
|
|
|
use std::fs::{File, OpenOptions}; |
|
|
|
use std::fs::{File, OpenOptions}; |
|
|
|
|
|
|
|
use std::io::{BufWriter, Read, Write}; |
|
|
|
|
|
|
|
use std::path::Path; |
|
|
|
|
|
|
|
|
|
|
|
/// Attempts to deserialize a Data struct from a string
|
|
|
|
/// Attempts to deserialize a Data struct from a string
|
|
|
|
pub fn from_str(s: &str) -> Result<AppData> { |
|
|
|
pub fn from_str(s: &str) -> Result<AppData> { |
|
|
@ -11,7 +11,7 @@ pub fn from_str(s: &str) -> Result<AppData> { |
|
|
|
|
|
|
|
|
|
|
|
/// Attempts to deserialize a Data struct from a slice of bytes
|
|
|
|
/// Attempts to deserialize a Data struct from a slice of bytes
|
|
|
|
pub fn from_slice(s: &[u8]) -> Result<AppData> { |
|
|
|
pub fn from_slice(s: &[u8]) -> Result<AppData> { |
|
|
|
Ok(toml::from_slice(s)?) |
|
|
|
Ok(from_str(&String::from_utf8_lossy(s))?) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/// Attempts to deserialize a Data struct from something that implements
|
|
|
|
/// Attempts to deserialize a Data struct from something that implements
|
|
|
@ -36,7 +36,7 @@ pub fn to_string(data: &AppData) -> Result<String> { |
|
|
|
|
|
|
|
|
|
|
|
/// Attempts to serialize a Data struct to a Vec of bytes
|
|
|
|
/// Attempts to serialize a Data struct to a Vec of bytes
|
|
|
|
pub fn to_vec(data: &AppData) -> Result<Vec<u8>> { |
|
|
|
pub fn to_vec(data: &AppData) -> Result<Vec<u8>> { |
|
|
|
Ok(toml::to_vec(data)?) |
|
|
|
Ok(toml::to_string(data)?.as_bytes().to_vec()) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/// Attempts to serialize a Data struct to something that implements the
|
|
|
|
/// Attempts to serialize a Data struct to something that implements the
|
|
|
|