mirror of
https://github.com/typst/typst
synced 2025-08-25 04:04:12 +08:00
Make #[synthesized]
fields #[internal]
This commit is contained in:
parent
3e7a39e968
commit
7576d3bc61
@ -78,9 +78,7 @@ impl Elem {
|
|||||||
|
|
||||||
/// Fields that show up in the documentation.
|
/// Fields that show up in the documentation.
|
||||||
fn doc_fields(&self) -> impl Iterator<Item = &Field> + Clone {
|
fn doc_fields(&self) -> impl Iterator<Item = &Field> + Clone {
|
||||||
self.fields
|
self.fields.iter().filter(|field| !field.internal)
|
||||||
.iter()
|
|
||||||
.filter(|field| !field.internal && !field.synthesized)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Fields that are relevant for `Construct` impl.
|
/// Fields that are relevant for `Construct` impl.
|
||||||
@ -89,9 +87,8 @@ impl Elem {
|
|||||||
/// because it's a pattern used a lot for parsing data from the input and
|
/// because it's a pattern used a lot for parsing data from the input and
|
||||||
/// then storing it in a field.
|
/// then storing it in a field.
|
||||||
fn construct_fields(&self) -> impl Iterator<Item = &Field> + Clone {
|
fn construct_fields(&self) -> impl Iterator<Item = &Field> + Clone {
|
||||||
self.real_fields().filter(|field| {
|
self.real_fields()
|
||||||
field.parse.is_some() || (!field.synthesized && !field.internal)
|
.filter(|field| field.parse.is_some() || !field.internal)
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Fields that can be configured with set rules.
|
/// Fields that can be configured with set rules.
|
||||||
@ -242,6 +239,8 @@ fn parse_field(field: &syn::Field) -> Result<Field> {
|
|||||||
let variadic = has_attr(&mut attrs, "variadic");
|
let variadic = has_attr(&mut attrs, "variadic");
|
||||||
let required = has_attr(&mut attrs, "required") || variadic;
|
let required = has_attr(&mut attrs, "required") || variadic;
|
||||||
let positional = has_attr(&mut attrs, "positional") || required;
|
let positional = has_attr(&mut attrs, "positional") || required;
|
||||||
|
let synthesized = has_attr(&mut attrs, "synthesized");
|
||||||
|
let internal = has_attr(&mut attrs, "internal") || synthesized;
|
||||||
|
|
||||||
let mut field = Field {
|
let mut field = Field {
|
||||||
ident: ident.clone(),
|
ident: ident.clone(),
|
||||||
@ -261,11 +260,11 @@ fn parse_field(field: &syn::Field) -> Result<Field> {
|
|||||||
variadic,
|
variadic,
|
||||||
resolve: has_attr(&mut attrs, "resolve"),
|
resolve: has_attr(&mut attrs, "resolve"),
|
||||||
fold: has_attr(&mut attrs, "fold"),
|
fold: has_attr(&mut attrs, "fold"),
|
||||||
internal: has_attr(&mut attrs, "internal"),
|
internal,
|
||||||
external: has_attr(&mut attrs, "external"),
|
external: has_attr(&mut attrs, "external"),
|
||||||
borrowed: has_attr(&mut attrs, "borrowed"),
|
borrowed: has_attr(&mut attrs, "borrowed"),
|
||||||
ghost: has_attr(&mut attrs, "ghost"),
|
ghost: has_attr(&mut attrs, "ghost"),
|
||||||
synthesized: has_attr(&mut attrs, "synthesized"),
|
synthesized,
|
||||||
parse: parse_attr(&mut attrs, "parse")?.flatten(),
|
parse: parse_attr(&mut attrs, "parse")?.flatten(),
|
||||||
default: parse_attr::<syn::Expr>(&mut attrs, "default")?.flatten(),
|
default: parse_attr::<syn::Expr>(&mut attrs, "default")?.flatten(),
|
||||||
};
|
};
|
||||||
|
@ -201,7 +201,9 @@ pub fn ty(stream: BoundaryStream, item: BoundaryStream) -> BoundaryStream {
|
|||||||
/// flexibility.
|
/// flexibility.
|
||||||
/// - `#[synthesized]`: The field cannot be specified in a constructor or set
|
/// - `#[synthesized]`: The field cannot be specified in a constructor or set
|
||||||
/// rule. Instead, it is added to an element before its show rule runs
|
/// rule. Instead, it is added to an element before its show rule runs
|
||||||
/// through the `Synthesize` trait.
|
/// through the `Synthesize` trait. This implies `#[internal]`. If a
|
||||||
|
/// synthesized field needs to be exposed to the user, that should be done via
|
||||||
|
/// a getter method.
|
||||||
/// - `#[ghost]`: Allows creating fields that are only present in the style chain,
|
/// - `#[ghost]`: Allows creating fields that are only present in the style chain,
|
||||||
/// this means that they *cannot* be accessed by the user, they cannot be set
|
/// this means that they *cannot* be accessed by the user, they cannot be set
|
||||||
/// on an individual instantiated element, and must be set via the style chain.
|
/// on an individual instantiated element, and must be set via the style chain.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user