Value

Enum Value 

Source
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>

Source

pub fn is_str(&self) -> bool

Returns true if this value is a string.

Source

pub fn is_obj(&self) -> bool

Returns true if this value is an object.

Source

pub fn is_i32(&self) -> bool

Returns true if this value is an i32.

Source

pub fn is_u64(&self) -> bool

Returns true if this value is a u64.

Source

pub fn is_float(&self) -> bool

Returns true if this value is a float.

Source

pub fn is_pointer(&self) -> bool

Returns true if this value is a pointer.

Source

pub fn is_color(&self) -> bool

Returns true if this value is a color.

Source

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}
Source

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}
Source

pub fn as_obj_mut(&mut self) -> Option<&mut Obj<'text>>

Returns a mutable reference to the object if this is an object.

Source

pub fn as_i32(&self) -> Option<i32>

Returns the i32 value if this is an i32.

Source

pub fn as_u64(&self) -> Option<u64>

Returns the u64 value if this is a u64.

Source

pub fn as_float(&self) -> Option<f32>

Returns the float value if this is a float.

Source

pub fn as_pointer(&self) -> Option<u32>

Returns the pointer value if this is a pointer.

Source

pub fn as_color(&self) -> Option<[u8; 4]>

Returns the color value if this is a color.

Source

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).

Source

pub fn get_path(&self, path: &[&str]) -> Option<&Value<'text>>

Traverse nested objects by path.

Returns None if any segment doesn’t exist or isn’t an object.

Source

pub fn get_str(&self, path: &[&str]) -> Option<&str>

Get a string at the given path.

Source

pub fn get_obj(&self, path: &[&str]) -> Option<&Obj<'text>>

Get an object at the given path.

Source

pub fn get_i32(&self, path: &[&str]) -> Option<i32>

Get an i32 at the given path.

Source

pub fn get_u64(&self, path: &[&str]) -> Option<u64>

Get a u64 at the given path.

Source

pub fn get_float(&self, path: &[&str]) -> Option<f32>

Get a float at the given path.

Source§

impl Value<'_>

Source

pub fn into_owned(self) -> Value<'static>

Convert to an owned version (with ’static lifetime).

Trait Implementations§

Source§

impl<'text> Clone for Value<'text>

Source§

fn clone(&self) -> Value<'text>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<'text> Debug for Value<'text>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'text> Display for Value<'text>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'text> From<&'text str> for Value<'text>

Source§

fn from(s: &'text str) -> Self

Converts to this type from the input type.
Source§

impl From<[u8; 4]> for Value<'static>

Source§

fn from(color: [u8; 4]) -> Self

Converts to this type from the input type.
Source§

impl<'text> From<Obj<'text>> for Value<'text>

Source§

fn from(obj: Obj<'text>) -> Self

Converts to this type from the input type.
Source§

impl From<String> for Value<'static>

Source§

fn from(s: String) -> Self

Converts to this type from the input type.
Source§

impl From<f32> for Value<'static>

Source§

fn from(n: f32) -> Self

Converts to this type from the input type.
Source§

impl From<i32> for Value<'static>

Source§

fn from(n: i32) -> Self

Converts to this type from the input type.
Source§

impl From<u32> for Value<'static>

Source§

fn from(n: u32) -> Self

Converts to this type from the input type.
Source§

impl From<u64> for Value<'static>

Source§

fn from(n: u64) -> Self

Converts to this type from the input type.
Source§

impl<'text> Index<&str> for Value<'text>

Source§

fn index(&self, key: &str) -> &Self::Output

Returns a reference to the value at the given key.

§Panics

Panics if this is not an object or if the key doesn’t exist. Use get() for non-panicking access.

Source§

type Output = Value<'text>

The returned type after indexing.
Source§

impl<'text> PartialEq for Value<'text>

Source§

fn eq(&self, other: &Value<'text>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.