Lines Matching full:example

54 /// struct Example {
59 /// // Create a ref-counted instance of `Example`.
60 /// let obj = Arc::try_new(Example { a: 10, b: 20 })?;
84 /// struct Example {
89 /// impl Example {
99 /// let obj = Arc::try_new(Example { a: 10, b: 20 })?;
105 /// Coercion from `Arc<Example>` to `Arc<dyn MyTrait>`:
118 /// struct Example;
119 /// impl MyTrait for Example {}
121 /// // `obj` has type `Arc<Example>`.
122 /// let obj: Arc<Example> = Arc::try_new(Example)?;
381 /// # Example
386 /// struct Example;
388 /// fn do_something(e: ArcBorrow<'_, Example>) -> Arc<Example> {
392 /// let obj = Arc::try_new(Example)?;
405 /// struct Example {
410 /// impl Example {
416 /// let obj = Arc::try_new(Example { a: 10, b: 20 })?;
491 /// In the following example, we make changes to the inner object before turning it into an
498 /// struct Example {
503 /// fn test() -> Result<Arc<Example>> {
504 /// let mut x = UniqueArc::try_new(Example { a: 10, b: 20 })?;
513 /// In the following example we first allocate memory for a ref-counted `Example` but we don't
515 /// followed by a conversion to `Arc<Example>`. This is particularly useful when allocation happens
521 /// struct Example {
526 /// fn test() -> Result<Arc<Example>> {
528 /// Ok(x.write(Example { a: 10, b: 20 }).into())
534 /// In the last example below, the caller gets a pinned instance of `Example` while converting to
535 /// `Arc<Example>`; this is useful in scenarios where one needs a pinned reference during
536 /// initialisation, for example, when initialising fields that are wrapped in locks.
541 /// struct Example {
546 /// fn test() -> Result<Arc<Example>> {
547 /// let mut pinned = Pin::from(UniqueArc::try_new(Example { a: 10, b: 20 })?);