Please check the build logs for more information.
See Builds for ideas on how to fix a failed build, or Metadata for how to configure docs.rs builds.
If you believe this is docs.rs' fault, open an issue.
fluent-impl
A procedural macro that generates chaining methods from non-chaining ones in an impl block.
When applied to an impl block, #[fluent_impl]
will scan all methods in the block
in search for chain-able methods, and generate chaining methods from them.
Chain-able methods are the ones with &mut self
as a first argument, and return nothing.
That's it, there are no other restrictions.
Detailed Build Status
fluent_impl
remains nightly-only, for now. The feature use_extern_macros
is
supposedly days away from stabilisation.
Travis
Linux | OSX |
---|---|
AppVeyor
AppVeyor Windows builds are failing now when running tests. This is probably caused by a bug in compiletest-rs. The crate should work just fine on Windows. Having said that, feedback from Windows users would be greatly appreciated.
Windows | x86_64 | i686 |
---|---|---|
nightly | ||
beta | ||
stable |
Usage
Add fluent-impl
to the dependencies in Cargo.toml
:
[]
= "0.1"
Then add the following to the top of src/lib.rs
:
// Will be stabilized soon
extern crate fluent_impl;
use ;
Examples
If we have a simple struct with a simple impl block:
Then we add the macro attribute to the impl block:
The macro will generate a new impl block with the content:
A full more involved example can be found bellow the Attribute Configuration section.
Attribute Configuration
#[fluent_impl]
is configurable with comma-separated options passed to the attribute
itself, and options passed to a method-level attribute #[fluent_impl_opts]
.
#[fluent_impl]
Attribute Options
(inblock
, non_public
, prefix
, impl_doc
, doc
)
impl block-level configuration.
Example
Options
-
inblock
(default: unset)By default, a new impl block is generated, and chaining methods are added there. If
inblock
is passed, every chaining method will be generated right below the chain-able one.The order in which methods appear on docs is probably the only reason why you should care about this.
There is a corresponding method-level
inblock
option which will selectively enable this behavior for individual methods. -
non_public
(default: unset)By default, non fully-public methods are skipped. If this option is passed, the macro will generate chaining equivalents for chain-able private or partially-public methods.
There is a corresponding method-level
non_public
option which will selectively enable this behavior for individual methods. -
prefix
(default: "with_")The default chaining method name is this prefix appended by the chain-able method name.
prefix
is not allowed to be an empty string. Check thename
method-level option if you want to name a chaining method to whatever you like.
There is a corresponding method-level
prefix
option which will selectively override the value set here (or the default). -
impl_doc
(default: "Chaining (fluent) methods for [`%t%`].")If a new block is generated for the chaining methods, this is the doc string template for it.
%t%
is is replaced with the type path. -
doc
(default: "The chaining (fluent) equivalent of [`%f%()`].")Chaining method doc string template.
%t%
is is replaced with the type path.%f%
is replaced with the chain-able method name.Additionally, the following is effectively appended at the end:
/// /// [`%f%`]: %t%::%f% /// [`%f%()`]: %t%::%f%
This allows proper hyper-linking of
[`%t%`]
and[`%t%()`]
.There is a corresponding method-level
doc
option which will selectively override the value set here (or the default).
#[fluent_impl_opts]
Attribute Options
(inblock
, non_public
, skip
, prefix
, rename
, name
, doc
)
Options passed to override block-level defaults, or set method-specific configurations.
Unlike #[fluent_impl]
, this attribute:
- Applies to methods instead of impl blocks.
- Can be passed multiple times to the same method if you please.
Example
Options
Inherited
-
inblock
(default: inherit)Set
inblock
for this specific method if it's not set for the block already. -
non_public
(default: inherit)Set
non_public
for this specific method if it's not set for the block already.This allows generating chaining methods for specific private methods, or partially public ones (e.g.
pub(crate)
methods). -
prefix
(default: inherit)Override the default, or the block value if set.
prefix
is not allowed to be an empty string.- Method-specific
prefix
is not allowed to be set ifname
(see below) is set.
-
doc
(default: inherit)Override the default, or the block value if set.
Method Specific
-
skip
(default: unset)Skip this method. Don't generate anything from it.
-
rename
(default: chain-able name)The default chaining method name is the prefix appended by the chain-able method name. This option allows you to rename the name that gets added to the prefix.
rename
is not allowed to be an empty string.rename
is not allowed to be set ifname
(see below) is set and vise versa.
-
name
(default: unset)Set the name of the chaining method.
name
is not allowed to be set if method-specificprefix
or rename is set.
Full Example
extern crate fluent_impl;