Oregami
Repositories/oxedyne/fe2o3

oxedyne/fe2o3/fe2o3_text/tests/detect_corpus/rust/canonical.txt

1.3 KiB, 1 run

created by r1870400018:12038, which is this file's identity for as long as the history lasts, whatever it is later renamed to

download · who wrote it · its history

1use std::collections::HashMap;
2use std::io::{self, BufRead};
3
4/// A simple key-value store backed by a hash map.
5pub struct Store {
6 data: HashMap<String, String>,
7 modified: bool,
8}
9
10impl Store {
11 /// Create an empty store.
12 pub fn new() -> Self {
13 Self {
14 data: HashMap::new(),
15 modified: false,
16 }
17 }
18
19 /// Insert a key-value pair, returning the old value if present.
20 pub fn insert(&mut self, key: String, value: String) -> Option<String> {
21 self.modified = true;
22 self.data.insert(key, value)
23 }
24
25 /// Retrieve a value by key.
26 pub fn get(&self, key: &str) -> Option<&String> {
27 self.data.get(key)
28 }
29
30 /// Return the number of entries.
31 pub fn len(&self) -> usize {
32 self.data.len()
33 }
34
35 /// Whether the store has been modified since creation.
36 pub fn is_modified(&self) -> bool {
37 self.modified
38 }
39}
40
41fn main() {
42 let mut store = Store::new();
43 let stdin = io::stdin();
44
45 for line in stdin.lock().lines() {
46 let line = line.expect("IO error");
47 let parts: Vec<&str> = line.splitn(2, '=').collect();
48 if parts.len() == 2 {
49 store.insert(parts[0].to_string(), parts[1].to_string());
50 }
51 }
52
53 println!("Stored {} entries, modified: {}", store.len(), store.is_modified());
54}