# Killing \`Ok(())\` with \`ok!()\`

**URL:** <https://internals.rust-lang.org/t/killing-ok-with-ok/21915>\
**Category:** libs\
**Created:** [November 25, 2024, 2:38am UTC](https://internals.rust-lang.org/t/killing-ok-with-ok/21915 "2024-11-25T02:38:15Z")\
**Posts on this page:** 1\
**Showing post:** 34

<div class="post-metadata">

**Author:** ![newpavlov](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/newpavlov/32/3290_2.png) [@newpavlov](https://internals.rust-lang.org/u/newpavlov)\
**Post date:** [December 2, 2024, 7:23pm UTC](https://internals.rust-lang.org/t/killing-ok-with-ok/21915/34 "2024-12-02T19:23:14Z")

</div>

With wrapping `try fn`s your snippet could look like this:

```rust
try fn foo(s: &[u8], what: &'static str) -> MyResult<String> {
    ffi::CStr::from_bytes_until_nul(s)
        .map_err(|e| MyError::NotCString(e, what))?
        .to_str()
        .map_err(|e| MyError::NotUTF8(e, what))?
        .to_string()
}

```

I think it's cleaner than your hypothetical `.Ok()`.

It's a bit off-topic, but with a helper library like [`snafu`](https://docs.rs/snafu) you can improve it a bit further:

```rust
try fn foo(s: &[u8], what: &'static str) -> MyResult<String> {
    ffi::CStr::from_bytes_until_nul(s)
        .context(NotCStringSnafu{ what })?
        .to_str()
        .context(NotUTF8Snafu { what })?
        .to_string()
}

```

---

_[View the full topic](https://internals.rust-lang.org/t/killing-ok-with-ok/21915)._
