Skip to content

Commit

Permalink
read and write yaml
Browse files Browse the repository at this point in the history
  • Loading branch information
jenna-a2ai committed Mar 21, 2024
1 parent b95273c commit b4349b8
Show file tree
Hide file tree
Showing 346 changed files with 810 additions and 28 deletions.
110 changes: 102 additions & 8 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
yaml-rust = "0.4"
serde = { version = "1.0", features = ["derive"] }
serde_yaml = "0.9"
2 changes: 1 addition & 1 deletion internal/config/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
)

type Config struct {
StorageDir string `yaml:"storage-dir`
StorageDir string `yaml:"storage-dir"`
}

var ConfigFileName = "dvs.yaml"
Expand Down
1 change: 1 addition & 0 deletions internal/config/temp2902199178/dvs.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
storagedir: ./temp2902199178
1 change: 1 addition & 0 deletions internal/config/temp414590490/dvs.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
storage-dir: ./temp414590490
1 change: 1 addition & 0 deletions internal/config/temp934345976/dvs.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
storagedir: ./temp934345976
35 changes: 18 additions & 17 deletions src/config.rs
Original file line number Diff line number Diff line change
@@ -1,31 +1,32 @@
use yaml_rust::{YamlLoader, YamlEmitter};
use std::{os, path};
use std::env;
use serde::{Serialize, Deserialize};
use std::fs;
use std::path::PathBuf;


#[derive(Serialize, Deserialize, PartialEq, Debug)]
pub struct Config {
storage_directory: String
pub storage_dir: PathBuf
}

impl Default for Config {
fn default() -> Self {
Config {storage_directory: String::from("yaml\":storage-dir")}
}
}

//static CONFIG_FILE_NAME: PathBuf = PathBuf::from(r"dvs.yaml");
//const CONFIG_FILE_NAME: &str = "dvs.yaml";

pub fn read(root_dir: PathBuf) {
let config_file_contents = fs::read_to_string(root_dir.join(PathBuf::from(r"dvs.yaml"))).unwrap();
pub fn read(root_dir: &PathBuf) -> Result<(), serde_yaml::Error> {
// check if yaml is readable
let yaml_contents = fs::read_to_string(root_dir.join(PathBuf::from(r"dvs.yaml"))).unwrap();

// match config_file_contents {
// Ok(contents) => {

// }
//let config = Config{storage_dir: root_dir.clone()};
//let yaml = serde_yaml::to_string(&config)?;
let deserialized_yaml: Config = serde_yaml::from_str(&yaml_contents)?;
Ok(())
//return deserialized_yaml;

} // read

pub fn write(config: &Config, dir: &PathBuf) -> std::io::Result<()> {
let yaml: String = serde_yaml::to_string(&config).unwrap();
fs::write(dir.join(PathBuf::from(r"dvs.yaml")), yaml)?;
Ok(())
}



Expand Down
1 change: 1 addition & 0 deletions src/dvs.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
storage_dir: /cluster-data/user-homes/jenna/Projects/devious/src
11 changes: 10 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
use std::path::PathBuf;

use config::{read, write};


mod config;

fn main() {
println!("Hello, world!");
let dir = PathBuf::from("/cluster-data/user-homes/jenna/Projects/devious/src");
let config = config::Config{storage_dir: dir.clone()};

write(&config, &dir);

read(&dir);
}
1 change: 1 addition & 0 deletions target/.rustc_info.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"rustc_fingerprint":6039375300803987626,"outputs":{"15729799797837862367":{"success":true,"status":"","code":0,"stdout":"___\nlib___.rlib\nlib___.so\nlib___.so\nlib___.a\nlib___.so\n/cluster-data/user-homes/jenna/.rustup/toolchains/stable-x86_64-unknown-linux-gnu\noff\npacked\nunpacked\n___\ndebug_assertions\npanic=\"unwind\"\nproc_macro\ntarget_arch=\"x86_64\"\ntarget_endian=\"little\"\ntarget_env=\"gnu\"\ntarget_family=\"unix\"\ntarget_feature=\"fxsr\"\ntarget_feature=\"sse\"\ntarget_feature=\"sse2\"\ntarget_has_atomic=\"16\"\ntarget_has_atomic=\"32\"\ntarget_has_atomic=\"64\"\ntarget_has_atomic=\"8\"\ntarget_has_atomic=\"ptr\"\ntarget_os=\"linux\"\ntarget_pointer_width=\"64\"\ntarget_vendor=\"unknown\"\nunix\n","stderr":""},"4614504638168534921":{"success":true,"status":"","code":0,"stdout":"rustc 1.76.0 (07dca489a 2024-02-04)\nbinary: rustc\ncommit-hash: 07dca489ac2d933c78d3c5158e3f43beefeb02ce\ncommit-date: 2024-02-04\nhost: x86_64-unknown-linux-gnu\nrelease: 1.76.0\nLLVM version: 17.0.6\n","stderr":""}},"successes":{}}
3 changes: 3 additions & 0 deletions target/CACHEDIR.TAG
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Signature: 8a477f597d28d172789f06886806bc55
# This file is a cache directory tag created by cargo.
# For information about cache directory tags see https://bford.info/cachedir/
Empty file added target/debug/.cargo-lock
Empty file.
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"rustc":18004373081649162931,"features":"[]","declared_features":"","target":4800893141602629679,"profile":5601947868832436996,"path":1684066648322511884,"deps":[[14371587128542172710,"yaml_rust",false,4259620847121773837]],"local":[{"CheckDepInfo":{"dep_info":"debug/.fingerprint/devious_rust-1b7a56223d48cdde/dep-bin-devious_rust"}}],"rustflags":[],"metadata":7797948686568424061,"config":2202906307356721367,"compile_kind":0}
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This file has an mtime of when this was started.
Loading

0 comments on commit b4349b8

Please sign in to comment.