@@ -19,6 +19,8 @@ ffcv is both a command-line tool and a Rust library for working with Firefox's `
1919- ** Powerful Querying** - Filter preferences using glob patterns like ` "network.*" ` or ` "browser.*.enabled" `
2020- ** Cross-Platform** - Automatic Firefox profile discovery on Linux, macOS, and Windows
2121- ** Rich Data Types** - Supports boolean, integer, float, string, and null values
22+ - ** Type-Safe API** - Convenience trait for easy value type checking and extraction
23+ - ** Simple Interface** - All public types and functions available at crate root
2224- ** Human-Readable Explanations** - Optional explanations for what preferences do
2325- ** Flexible Output** - JSON output with customizable formatting
2426- ** Well-Tested** - Comprehensive test coverage with robust error handling
@@ -41,7 +43,7 @@ Add to your `Cargo.toml`:
4143
4244``` toml
4345[dependencies ]
44- ffcv = " 1.0"
46+ ffcv = " 1.0.1 "
4547```
4648
4749## Command-Line Usage
@@ -87,12 +89,12 @@ ffcv config view default --file /path/to/prefs.js
8789### Basic Parsing
8890
8991``` rust
90- use ffcv :: parser :: parse_prefs ;
92+ use ffcv :: parse_prefs_js ;
9193use std :: fs;
9294
9395fn main () -> Result <(), Box <dyn std :: error :: Error >> {
9496 let content = fs :: read_to_string (" prefs.js" )? ;
95- let entries = parse_prefs (& content )? ;
97+ let entries = parse_prefs_js (& content )? ;
9698
9799 for entry in entries {
98100 println! (" {:?} = {:?}" , entry . key, entry . value);
@@ -105,19 +107,18 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
105107### Query Preferences
106108
107109``` rust
108- use ffcv :: parser :: parse_prefs;
109- use ffcv :: query :: QueryMatcher ;
110+ use ffcv :: {parse_prefs_js, query_preferences};
110111use std :: fs;
111112
112113fn main () -> Result <(), Box <dyn std :: error :: Error >> {
113114 let content = fs :: read_to_string (" prefs.js" )? ;
114- let entries = parse_prefs (& content )? ;
115+ let entries = parse_prefs_js (& content )? ;
115116
116- // Create a matcher for network-related preferences
117- let matcher = QueryMatcher :: new ( vec! [" network.*" ])? ;
117+ // Query network-related preferences
118+ let network_prefs = query_preferences ( & entries , & [" network.*" ])? ;
118119
119- // Filter and display matching entries
120- for entry in entries . into_iter () . filter ( | e | matcher . matches ( & e . key)) {
120+ // Display matching entries
121+ for entry in network_prefs {
121122 println! (" {} = {:?}" , entry . key, entry . value);
122123 }
123124
@@ -128,11 +129,10 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
128129### Profile Discovery
129130
130131``` rust
131- use ffcv :: profile :: ProfileFinder ;
132+ use ffcv :: list_profiles ;
132133
133134fn main () -> Result <(), Box <dyn std :: error :: Error >> {
134- let finder = ProfileFinder :: new ()? ;
135- let profiles = finder . find_profiles ()? ;
135+ let profiles = list_profiles (None )? ;
136136
137137 for profile in profiles {
138138 println! (" Profile: {}" , profile . name);
@@ -147,19 +147,61 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
147147### Working with Preference Values
148148
149149``` rust
150- use ffcv :: types :: {PrefEntry , PrefValue };
150+ use ffcv :: {PrefEntry , PrefValue , PrefValueExt };
151151
152152fn process_entry (entry : PrefEntry ) {
153- match entry . value {
154- PrefValue :: Bool (true ) => println! (" {} is enabled" , entry . key),
155- PrefValue :: Bool (false ) => println! (" {} is disabled" , entry . key),
156- PrefValue :: Int (n ) => println! (" {} = {} (integer)" , entry . key, n ),
157- PrefValue :: String (ref s ) => println! (" {} = \ " {}\ "" , entry . key, s ),
158- _ => println! (" {} = {:?}" , entry . key, entry . value),
153+ // Use convenience methods from PrefValueExt trait
154+ if let Some (enabled ) = entry . value. as_bool () {
155+ if enabled {
156+ println! (" {} is enabled" , entry . key);
157+ } else {
158+ println! (" {} is disabled" , entry . key);
159+ }
160+ } else if let Some (n ) = entry . value. as_int () {
161+ println! (" {} = {} (integer)" , entry . key, n );
162+ } else if let Some (s ) = entry . value. as_string () {
163+ println! (" {} = \ " {}\ "" , entry . key, s );
164+ } else {
165+ println! (" {} = {:?}" , entry . key, entry . value);
159166 }
160167}
161168```
162169
170+ ### Finding a Specific Profile
171+
172+ ``` rust
173+ use ffcv :: find_profile_path;
174+
175+ fn main () -> Result <(), Box <dyn std :: error :: Error >> {
176+ // Find a specific Firefox profile by name
177+ let profile_path = find_profile_path (" default" , None )? ;
178+
179+ println! (" Profile path: {}" , profile_path . display ());
180+
181+ Ok (())
182+ }
183+ ```
184+
185+ ## API Design
186+
187+ ffcv provides a clean, simplified API with all public types and functions available at the crate root:
188+
189+ ** Core Types:**
190+ - ` PrefEntry ` - A single preference entry with key, value, and type
191+ - ` PrefType ` - The type of preference (User, Default, Locked, Sticky)
192+ - ` PrefValue ` - The value of a preference (Bool, Int, Float, String, Null)
193+ - ` PrefValueExt ` - Convenience trait for type-safe value access
194+
195+ ** Core Functions:**
196+ - ` parse_prefs_js() ` - Parse preference file contents
197+ - ` parse_prefs_js_file() ` - Parse directly from a file path
198+ - ` query_preferences() ` - Filter preferences by glob patterns
199+ - ` list_profiles() ` - List all Firefox profiles
200+ - ` find_profile_path() ` - Find a specific profile by name
201+ - ` get_prefs_path() ` - Get the prefs.js path for a profile
202+
203+ All functions return ` Result<T, Error> ` for proper error handling.
204+
163205## Preference Types
164206
165207Firefox uses several types of preferences:
@@ -216,6 +258,10 @@ This project is dual-licensed under either:
216258
217259You may choose either license for your use.
218260
261+ ## Version 1.0
262+
263+ ffcv provides a stable and well-tested API. The library offers a clean, simplified interface with comprehensive Firefox preference parsing capabilities. All public types and functions are available at the crate root for easy importing.
264+
219265## Acknowledgments
220266
221267Built for the Rust community to make Firefox configuration management easier and more programmatic.
0 commit comments