Skip to main content

RefContext

Struct RefContext 

Source
pub struct RefContext<'a> {
    pub program: Option<&'a str>,
    pub py_module: Option<&'a str>,
    pub py_class: Option<&'a str>,
    pub py_class_key: bool,
    pub py_module_key: bool,
    pub py_classes_key: bool,
    pub py_modules_key: bool,
}
Expand description

The slice of sphinx’s env.ref_context the inline roles read: the values OptionXRefRole/PyXRefRole stamp on their pending_xrefs, plus the key-existence flags AnyXRefRole.process_link’s blanket refnode.attributes.update(env.ref_context) (sphinx/roles.py) needs — a ref_context key can exist holding Python None (pformat’s "True" sentinel) or a list that the balanced directive nesting has drained back to [] (pformat "") by the time the doctree is serialized, so a bare Option<&str> cannot distinguish “absent” from those.

Fields§

§program: Option<&'a str>

env.ref_context['std:program'] — the .. program:: in scope, which OptionXRefRole.process_link stamps on every :option: reference (domains/std/__init__.py:351-364).

§py_module: Option<&'a str>

env.ref_context['py:module'] / ['py:class'] — the enclosing module/class scope PyXRefRole.process_link stamps on every py pending_xref (domains/python/__init__.py:568-569).

Like Self::py_class, this None cannot by itself distinguish “the key is absent” from “the key exists holding None” — which is why Self::py_module_key exists. The distinction is reachable: before_content pushes ref_context.get('py:module'), which is None when a :module:-carrying directive has no enclosing module scope, and after_content then ASSIGNS that None back (if modules: is true for a one-element list holding None, _object.py:498-503) instead of popping the key. Research spec §8 trap 14 says the same. The :any: role’s blanket ref_context copy is where it shows, as the "True" sentinel.

§py_class: Option<&'a str>§py_class_key: bool

'py:class' in env.ref_context: true once any py object directive set a class prefix (before_content) or completed (after_content always assigns the key, _object.py:482-503) — the value may be None (py_class absent), which the :any: role still stamps.

§py_module_key: bool

'py:module' in env.ref_context: true while a module scope is set AND after a :module:-carrying directive has closed, where the key survives holding None. Cleared by .. py:currentmodule:: None (ref_context.pop).

§py_classes_key: bool

'py:classes' in env.ref_context: created by before_content for nesting kinds and unconditionally by after_content’s setdefault. The list is what AnyXRefRole copies onto the node, and balanced nesting drains it to [] by end of parse — so it renders "".

§py_modules_key: bool

'py:modules' in env.ref_context: created when a :module: option pushed (before_content/after_content, _object.py:477-480). Same aliased-list story as py_classes_key: always drained.

Trait Implementations§

Source§

impl<'a> Clone for RefContext<'a>

Source§

fn clone(&self) -> RefContext<'a>

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl<'a> Copy for RefContext<'a>

Source§

impl<'a> Default for RefContext<'a>

Source§

fn default() -> RefContext<'a>

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl<'a> Freeze for RefContext<'a>

§

impl<'a> RefUnwindSafe for RefContext<'a>

§

impl<'a> Send for RefContext<'a>

§

impl<'a> Sync for RefContext<'a>

§

impl<'a> Unpin for RefContext<'a>

§

impl<'a> UnsafeUnpin for RefContext<'a>

§

impl<'a> UnwindSafe for RefContext<'a>

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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, 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.