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>
impl<'a> Clone for RefContext<'a>
Source§fn clone(&self) -> RefContext<'a>
fn clone(&self) -> RefContext<'a>
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreimpl<'a> Copy for RefContext<'a>
Source§impl<'a> Default for RefContext<'a>
impl<'a> Default for RefContext<'a>
Source§fn default() -> RefContext<'a>
fn default() -> RefContext<'a>
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
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