/* This Source Code Form is subject to the terms of the Mozilla Public *License,v.2.0.IfacopyoftheMPLwasnotdistributedwiththis
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
mod error; mod fs; mod owned_value; pubmod skv; mod task;
use atomic_refcell::AtomicRefCell; use error::KeyValueError; use libc::c_void; use moz_task::{create_background_task_queue, DispatchOptions, TaskRunnable}; use nserror::{nsresult, NS_ERROR_FAILURE, NS_ERROR_NOT_IMPLEMENTED, NS_OK}; use nsstring::{nsACString, nsAString, nsCString, nsString}; use owned_value::{owned_to_variant, variant_to_owned}; use rkv::backend::{RecoveryStrategy, SafeModeDatabase, SafeModeEnvironment}; use rkv::OwnedValue; use std::{
ptr,
sync::{Arc, RwLock},
vec::IntoIter,
}; use task::{
ClearTask, DeleteTask, EnumerateTask, GetOrCreateWithOptionsTask, GetTask, HasTask, PutTask,
WriteManyTask,
}; use thin_vec::ThinVec; use xpcom::{
getter_addrefs,
interfaces::{
nsIKeyValueDatabaseCallback, nsIKeyValueEnumeratorCallback, nsIKeyValueImporter,
nsIKeyValuePair, nsIKeyValueService, nsIKeyValueVariantCallback, nsIKeyValueVoidCallback,
nsISerialEventTarget, nsIVariant,
},
nsIID, xpcom, xpcom_method, RefPtr,
};
type Rkv = rkv::Rkv<SafeModeEnvironment>; type SingleStore = rkv::SingleStore<SafeModeDatabase>; type KeyValuePairResult = Result<(String, OwnedValue), KeyValueError>;
let service = KeyValueService::new();
service.QueryInterface(iid, result)
}
// For each public XPCOM method in the nsIKeyValue* interfaces, we implement // a pair of Rust methods: // // 1. a method named after the XPCOM (as modified by the XPIDL parser, i.e. // by capitalization of its initial letter) that returns an nsresult; // // 2. a method with a Rust-y name that returns a Result<(), KeyValueError>. // // XPCOM calls the first method, which is only responsible for calling // the second one and converting its Result to an nsresult (logging errors // in the process). The second method is responsible for doing the work. // // For example, given an XPCOM method FooBar, we implement a method FooBar // that calls a method foo_bar. foo_bar returns a Result<(), KeyValueError>, // and FooBar converts that to an nsresult. // // This design allows us to use Rust idioms like the question mark operator // to simplify the implementation in the second method while returning XPCOM- // compatible nsresult values to XPCOM callers. // // The XPCOM methods are implemented using the xpcom_method! declarative macro // from the xpcom crate.
fn get_next(&self) -> Result<RefPtr<nsIKeyValuePair>, KeyValueError> { letmut iter = self.iter.borrow_mut(); let (key, value) = iter
.next()
.ok_or_else(|| KeyValueError::from(NS_ERROR_FAILURE))??;
// We fail on retrieval of the key/value pair if the key isn't valid // UTF-*, if the value is unexpected, or if we encountered a store error // while retrieving the pair.
Ok(RefPtr::new(
KeyValuePair::new(key, value).coerce::<nsIKeyValuePair>(),
))
}
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.