tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

resource.rs (1028B)


      1 /* This Source Code Form is subject to the terms of the Mozilla Public
      2 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
      3 * You can obtain one at http://mozilla.org/MPL/2.0/. */
      4 
      5 pub use fluent::FluentResource;
      6 use nsstring::nsACString;
      7 use std::{
      8    mem::{self, ManuallyDrop},
      9    rc::Rc,
     10 };
     11 
     12 #[no_mangle]
     13 pub extern "C" fn fluent_resource_new(
     14    name: &nsACString,
     15    has_errors: &mut bool,
     16 ) -> *const FluentResource {
     17    let res = match FluentResource::try_new(name.to_string()) {
     18        Ok(res) => {
     19            *has_errors = false;
     20            res
     21        }
     22        Err((res, _)) => {
     23            *has_errors = true;
     24            res
     25        }
     26    };
     27    Rc::into_raw(Rc::new(res))
     28 }
     29 
     30 #[no_mangle]
     31 pub unsafe extern "C" fn fluent_resource_addref(res: *const FluentResource) {
     32    let raw = ManuallyDrop::new(Rc::from_raw(res));
     33    mem::forget(Rc::clone(&raw));
     34 }
     35 
     36 #[no_mangle]
     37 pub unsafe extern "C" fn fluent_resource_release(res: *const FluentResource) {
     38    let _ = Rc::from_raw(res);
     39 }