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)?;
339 /// # Example
344 /// struct Example;
346 /// fn do_something(e: ArcBorrow<'_, Example>) -> Arc<Example> {
350 /// let obj = Arc::try_new(Example)?;
363 /// struct Example {
368 /// impl Example {
374 /// let obj = Arc::try_new(Example { a: 10, b: 20 })?;
449 /// In the following example, we make changes to the inner object before turning it into an
456 /// struct Example {
461 /// fn test() -> Result<Arc<Example>> {
462 /// let mut x = UniqueArc::try_new(Example { a: 10, b: 20 })?;
471 /// In the following example we first allocate memory for a ref-counted `Example` but we don't
473 /// followed by a conversion to `Arc<Example>`. This is particularly useful when allocation happens
479 /// struct Example {
484 /// fn test() -> Result<Arc<Example>> {
486 /// Ok(x.write(Example { a: 10, b: 20 }).into())
492 /// In the last example below, the caller gets a pinned instance of `Example` while converting to
493 /// `Arc<Example>`; this is useful in scenarios where one needs a pinned reference during
494 /// initialisation, for example, when initialising fields that are wrapped in locks.
499 /// struct Example {
504 /// fn test() -> Result<Arc<Example>> {
505 /// let mut pinned = Pin::from(UniqueArc::try_new(Example { a: 10, b: 20 })?);