diff options
author | Federico Mena Quintero <federico@gnome.org> | 2022-08-22 13:45:21 -0500 |
---|---|---|
committer | Federico Mena Quintero <federico@gnome.org> | 2022-08-22 13:45:21 -0500 |
commit | 2e5b95385838682aa3fe0edd119f2cb39a816f79 (patch) | |
tree | 42d8842d4499a0b053caf8d5d06877804633edfb | |
parent | 4231dc23e806bf53f1a1304851421d1a1e90bb07 (diff) | |
download | librsvg-2e5b95385838682aa3fe0edd119f2cb39a816f79.tar.gz |
Session: move the fields to an inner Arc<T>
It's going to be miserable to deref this everywhere, especially once
we start having a mutex in there.
Part-of: <https://gitlab.gnome.org/GNOME/librsvg/-/merge_requests/731>
-rw-r--r-- | src/api.rs | 9 | ||||
-rw-r--r-- | src/handle.rs | 6 | ||||
-rw-r--r-- | src/session.rs | 15 |
3 files changed, 20 insertions, 10 deletions
@@ -13,7 +13,6 @@ pub use crate::{ use url::Url; use std::path::Path; -use std::sync::Arc; use gio::prelude::*; // Re-exposes glib's prelude as well use gio::Cancellable; @@ -36,7 +35,7 @@ use crate::{ pub struct Loader { unlimited_size: bool, keep_image_data: bool, - session: Arc<Session>, + session: Session, } impl Loader { @@ -60,14 +59,14 @@ impl Loader { /// .unwrap(); /// ``` pub fn new() -> Self { - Self::new_with_session(Arc::new(Session::new())) + Self::new_with_session(Session::new()) } /// Creates a `Loader` from a pre-created [`Session`]. /// /// This is useful when a `Loader` must be created by the C API, which should already /// have created a session for logging. - pub(crate) fn new_with_session(session: Arc<Session>) -> Self { + pub(crate) fn new_with_session(session: Session) -> Self { Self { unlimited_size: false, keep_image_data: false, @@ -233,7 +232,7 @@ fn url_from_file(file: &gio::File) -> Result<Url, LoadingError> { /// You can create this from one of the `read` methods in /// [`Loader`]. pub struct SvgHandle { - session: Arc<Session>, + session: Session, pub(crate) handle: Handle, } diff --git a/src/handle.rs b/src/handle.rs index 541e3877..99827816 100644 --- a/src/handle.rs +++ b/src/handle.rs @@ -2,8 +2,6 @@ //! //! This module provides the primitives on which the public APIs are implemented. -use std::sync::Arc; - use crate::accept_language::UserLanguage; use crate::bbox::BoundingBox; use crate::css::{Origin, Stylesheet}; @@ -82,14 +80,14 @@ impl LoadOptions { /// /// [`from_stream`]: #method.from_stream pub struct Handle { - session: Arc<Session>, + session: Session, document: Document, } impl Handle { /// Loads an SVG document into a `Handle`. pub fn from_stream( - session: Arc<Session>, + session: Session, load_options: &LoadOptions, stream: &gio::InputStream, cancellable: Option<&gio::Cancellable>, diff --git a/src/session.rs b/src/session.rs index 8988f2fd..e363e8e7 100644 --- a/src/session.rs +++ b/src/session.rs @@ -1,5 +1,7 @@ //! Tracks metadata for a loading/rendering session. +use std::sync::Arc; + use crate::log; /// Metadata for a loading/rendering session. @@ -7,14 +9,25 @@ use crate::log; /// When the calling program first uses one of the API entry points (e.g. `Loader::new()` /// in the Rust API, or `rsvg_handle_new()` in the C API), there is no context yet where /// librsvg's code may start to track things. This struct provides that context. +#[derive(Clone)] pub struct Session { + inner: Arc<SessionInner>, +} + +struct SessionInner { log_enabled: bool, } impl Session { pub fn new() -> Self { Self { - log_enabled: log::log_enabled(), + inner: Arc::new(SessionInner { + log_enabled: log::log_enabled(), + }), } } + + pub fn log_enabled(&self) -> bool { + self.inner.log_enabled + } } |