onlytypes 0.1.4

A library for creating types that can only be created by a certain function
Documentation
# Attempts to stub out what ever you give it


If you give it a function, the function will compile, but panic at runtime.

## Examples


### Stubbing a certain implementation of a trait


```rust
use std::fmt;

pub struct Something;

impl fmt::Debug for Something {
    #[onlytypes::stub]// Will stub this function (but still compile)
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        write!(f, "Something")
    }
}
```

### Stubbing a function


```rust
#[onlytypes::stub]

pub fn something() -> String {
    "Something".to_string()
}
```

### Stubbing the whole impl block


```rust
struct SomethingStruct;
trait SomethingTrait {
    fn something(&self) -> String;
    fn something_else(&self) -> String;
}
#[onlytypes::stub]

impl SomethingTrait for SomethingStruct {
    fn something(&self) -> String {
        "Something".to_string()
    }
    fn something_else(&self) -> String {
        "Something else".to_string()
    }
}
```

### Stubbing a very complex function


```rust
#[onlytypes::stub]

pub async fn async_func() -> u32 {
    42
}
#[onlytypes::stub]

pub const unsafe extern "C" fn usually_ffi() -> u32 {
    42
}
```

### Stubbing where clauses


```rust
struct SomethingStruct<T>(T);

#[onlytypes::stub]

impl<T> SomethingStruct<T>
where
    T: ToString,
{
    pub fn get<F>(&self, f: F) -> String where
        F: FnOnce() -> T
    {
        f().to_string()
    }
}

trait SomethingTrait<T> {
    type Output;
    fn something(&self) -> &T;
    fn something_else(&self) -> Self::Output;
}

#[onlytypes::stub]

impl<T> SomethingTrait<T> for SomethingStruct<T> where
    T: ToString,
{
    type Output = String;
    fn something(&self) -> &T {
        &self.0
    }
    fn something_else(&self) -> Self::Output {
        self.0.to_string()
    }
}
```

### Stubbing return impl Trait


```rust
#[onlytypes::stub]

pub fn returns_impl() -> impl std::fmt::Debug {
    42
}

#[onlytypes::stub]

pub fn returns_impl_future() -> impl std::future::Future<Output = u32> {
    async { 42 }
}

#[onlytypes::stub]

pub fn returns_iter<'a>() -> impl Iterator<Item = u32> + 'a {
    vec![42].into_iter()
}
```

### Other Complex Examples


```rust
struct SomethingStruct<T>(T);
struct SomethingElseStruct<T>(T);

#[onlytypes::stub]

impl<S> SomethingStruct<S> where
    S: ToString
{
    pub fn very_complex_func<'a, T>(
        &mut self,
        name: T,
    ) -> impl Iterator<Item = Result<SomethingElseStruct<&'a str>,()>>
    where
        T: Into<&'a str>,
    {
        vec![Ok(SomethingElseStruct(name.into()))].into_iter()
    }
}
```