Interpolate escape characters in strings

I have some strings with literal escape characters in them. I want to interpolate the string so that escaped characters are properly replaced (i.e. \n is replaced with a newline, \t is replaced with a tab, etc). Essentially I am looking for some_magic_function in the example below

    assert_eq!("foo\nbar", some_magic_function(r#"foo\nbar"#));

Does rust have something that can do this?

That depends what kinds of escape sequences you're planning to support. Regardless, the code for doing this is fairly trivial (see here for how the unescape crate does it, for example.)