pub enum Value<'text> {
Str(Cow<'text, str>),
Obj(Obj<'text>),
I32(i32),
U64(u64),
Float(f32),
Pointer(u32),
Color([u8; 4]),
}Expand description
VDF Value - can be a string, number, object, or other types
Variants§
Str(Cow<'text, str>)
A string value (text format and WideString from binary)
Obj(Obj<'text>)
An object containing nested key-value pairs
I32(i32)
A 32-bit signed integer (binary Int32 type)
U64(u64)
A 64-bit unsigned integer (binary UInt64 type)
Float(f32)
A 32-bit float (binary Float type)
Pointer(u32)
A pointer value (binary Ptr type, stored as u32)
Color([u8; 4])
A color value (binary Color type, RGBA)
Implementations§
Source§impl<'text> Value<'text>
impl<'text> Value<'text>
Sourcepub fn is_pointer(&self) -> bool
pub fn is_pointer(&self) -> bool
Returns true if this value is a pointer.
Sourcepub fn as_str(&self) -> Option<&str>
pub fn as_str(&self) -> Option<&str>
Returns a reference to the string value if this is a string.
Examples found in repository?
examples/appid_to_name.rs (line 82)
17fn main() -> ExitCode {
18 let args: Vec<String> = env::args().collect();
19
20 if args.len() < 2 {
21 eprintln!("Usage: {} <path/to/appinfo.vdf>", args[0]);
22 eprintln!();
23 eprintln!("Extracts AppId to game name mappings from Steam's appinfo.vdf file.");
24 eprintln!();
25 eprintln!("The appinfo.vdf file is typically located at:");
26 eprintln!(" Windows: C:\\Program Files (x86)\\Steam\\appcache\\appinfo.vdf");
27 eprintln!(" Linux: ~/.steam/steam/appcache/appinfo.vdf");
28 eprintln!(" macOS: ~/Library/Application Support/Steam/appcache/appinfo.vdf");
29 return ExitCode::FAILURE;
30 }
31
32 let path = &args[1];
33
34 // Read the file
35 let data = match fs::read(path) {
36 Ok(data) => data,
37 Err(e) => {
38 eprintln!("Error reading file '{}': {}", path, e);
39 return ExitCode::FAILURE;
40 }
41 };
42
43 // Parse the appinfo.vdf file
44 let vdf = match parse_appinfo(&data) {
45 Ok(vdf) => vdf.into_owned(),
46 Err(e) => {
47 eprintln!("Error parsing appinfo.vdf: {}", e);
48 return ExitCode::FAILURE;
49 }
50 };
51
52 // Get the root object containing all apps
53 let root = match vdf.as_obj() {
54 Some(obj) => obj,
55 None => {
56 eprintln!("Error: root is not an object");
57 return ExitCode::FAILURE;
58 }
59 };
60
61 // Iterate through all apps (keyed by AppID as string)
62 let mut apps = Vec::new();
63
64 for (app_id_str, app_value) in root.iter() {
65 // Skip non-numeric keys (metadata entries)
66 if app_id_str.parse::<u32>().is_err() {
67 continue;
68 }
69
70 let app_obj = match app_value.as_obj() {
71 Some(obj) => obj,
72 None => continue,
73 };
74
75 // Navigate the nested structure: appinfo -> common -> name
76 let name = app_obj
77 .get("appinfo")
78 .and_then(|v| v.as_obj())
79 .and_then(|appinfo| appinfo.get("common"))
80 .and_then(|common| common.as_obj())
81 .and_then(|common| common.get("name"))
82 .and_then(|v| v.as_str());
83
84 if let (Some(name), Ok(app_id)) = (name, app_id_str.parse::<u32>()) {
85 apps.push((app_id, name.to_string()));
86 }
87 }
88
89 // Sort by AppID
90 apps.sort_by_key(|(id, _)| *id);
91
92 // Print the results
93 println!("AppId\tName");
94 println!("------\t{}", "-".repeat(80));
95 for (app_id, name) in &apps {
96 println!("{}\t{}", app_id, name);
97 }
98
99 println!();
100 println!("Total games: {}", apps.len());
101
102 ExitCode::SUCCESS
103}Sourcepub fn as_obj(&self) -> Option<&Obj<'text>>
pub fn as_obj(&self) -> Option<&Obj<'text>>
Returns a reference to the object if this is an object.
Examples found in repository?
examples/appid_to_name.rs (line 70)
17fn main() -> ExitCode {
18 let args: Vec<String> = env::args().collect();
19
20 if args.len() < 2 {
21 eprintln!("Usage: {} <path/to/appinfo.vdf>", args[0]);
22 eprintln!();
23 eprintln!("Extracts AppId to game name mappings from Steam's appinfo.vdf file.");
24 eprintln!();
25 eprintln!("The appinfo.vdf file is typically located at:");
26 eprintln!(" Windows: C:\\Program Files (x86)\\Steam\\appcache\\appinfo.vdf");
27 eprintln!(" Linux: ~/.steam/steam/appcache/appinfo.vdf");
28 eprintln!(" macOS: ~/Library/Application Support/Steam/appcache/appinfo.vdf");
29 return ExitCode::FAILURE;
30 }
31
32 let path = &args[1];
33
34 // Read the file
35 let data = match fs::read(path) {
36 Ok(data) => data,
37 Err(e) => {
38 eprintln!("Error reading file '{}': {}", path, e);
39 return ExitCode::FAILURE;
40 }
41 };
42
43 // Parse the appinfo.vdf file
44 let vdf = match parse_appinfo(&data) {
45 Ok(vdf) => vdf.into_owned(),
46 Err(e) => {
47 eprintln!("Error parsing appinfo.vdf: {}", e);
48 return ExitCode::FAILURE;
49 }
50 };
51
52 // Get the root object containing all apps
53 let root = match vdf.as_obj() {
54 Some(obj) => obj,
55 None => {
56 eprintln!("Error: root is not an object");
57 return ExitCode::FAILURE;
58 }
59 };
60
61 // Iterate through all apps (keyed by AppID as string)
62 let mut apps = Vec::new();
63
64 for (app_id_str, app_value) in root.iter() {
65 // Skip non-numeric keys (metadata entries)
66 if app_id_str.parse::<u32>().is_err() {
67 continue;
68 }
69
70 let app_obj = match app_value.as_obj() {
71 Some(obj) => obj,
72 None => continue,
73 };
74
75 // Navigate the nested structure: appinfo -> common -> name
76 let name = app_obj
77 .get("appinfo")
78 .and_then(|v| v.as_obj())
79 .and_then(|appinfo| appinfo.get("common"))
80 .and_then(|common| common.as_obj())
81 .and_then(|common| common.get("name"))
82 .and_then(|v| v.as_str());
83
84 if let (Some(name), Ok(app_id)) = (name, app_id_str.parse::<u32>()) {
85 apps.push((app_id, name.to_string()));
86 }
87 }
88
89 // Sort by AppID
90 apps.sort_by_key(|(id, _)| *id);
91
92 // Print the results
93 println!("AppId\tName");
94 println!("------\t{}", "-".repeat(80));
95 for (app_id, name) in &apps {
96 println!("{}\t{}", app_id, name);
97 }
98
99 println!();
100 println!("Total games: {}", apps.len());
101
102 ExitCode::SUCCESS
103}Sourcepub fn as_obj_mut(&mut self) -> Option<&mut Obj<'text>>
pub fn as_obj_mut(&mut self) -> Option<&mut Obj<'text>>
Returns a mutable reference to the object if this is an object.
Sourcepub fn as_pointer(&self) -> Option<u32>
pub fn as_pointer(&self) -> Option<u32>
Returns the pointer value if this is a pointer.
Sourcepub fn get(&self, key: &str) -> Option<&Value<'text>>
pub fn get(&self, key: &str) -> Option<&Value<'text>>
Returns a reference to a nested value by key.
Shorthand for self.as_obj()?.get(key).
Trait Implementations§
impl<'text> StructuralPartialEq for Value<'text>
Auto Trait Implementations§
impl<'text> Freeze for Value<'text>
impl<'text> RefUnwindSafe for Value<'text>
impl<'text> Send for Value<'text>
impl<'text> Sync for Value<'text>
impl<'text> Unpin for Value<'text>
impl<'text> UnwindSafe for Value<'text>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more