---
title: ToMethod
summary: Types that can be converted to a Method.
url: https://www.fastly.com/documentation/reference/compute/sdks/rust/fastly/convert/trait.ToMethod/
---

**Kind:** Trait  
**Module:** [convert](https://www.fastly.com/documentation/reference/compute/sdks/rust/fastly/convert/)  
**Package:** fastly 0.13.1  
**Source:** https://docs.rs/crate/fastly/0.13.1/source/src/convert.rs#196

```rust
pub trait ToMethod: Sealed { }
```

Types that can be converted to a [`Method`](https://docs.rs/http/latest/http/method/struct.Method.html).

Some methods in this crate accept `impl ToMethod` arguments. Any of the types below can be
passed as those arguments and the conversion will be performed automatically, though
depending on the type, the conversion can panic.

| Source type                                                | Can panic? | Non-panicking conversion |
|------------------------------------------------------------|------------|--------------------------|
| [`Method` or `&Method`](https://docs.rs/http/latest/http/method/struct.Method.html)                          | No         | N/A                      |
| [`&str`](https://doc.rust-lang.org/stable/std/primitive.str.html), [`String`, or `&String`](https://doc.rust-lang.org/stable/alloc/string/struct.String.html)        | Yes        | [`Method::try_from()`](https://docs.rs/http/latest/http/method/Method/fn.try_from.html)   |
| [`&[u8]`][`std::slice`](https://doc.rust-lang.org/stable/alloc/slice/index.html), [`Vec<u8>`, or `&Vec<u8>`](https://doc.rust-lang.org/stable/alloc/vec/struct.Vec.html) | Yes        | [`Method::try_from()`](https://docs.rs/http/latest/http/method/Method/fn.try_from.html)   |

## Panics

This conversion trait differs from [`std::convert::Into`](https://doc.rust-lang.org/stable/core/convert/trait.Into.html), which is guaranteed to succeed for any
argument, and [`std::convert::TryInto`](https://doc.rust-lang.org/stable/core/convert/trait.TryInto.html) which returns an explicit error when a conversion fails.

For types marked above as **Can panic?**, the conversion may panic at runtime if the data is
invalid. Automatic conversions for these types are provided for convenience for data you trust, like
a string literal in your code, or for applications where a default `500 Internal Server Error`
response for a conversion failure is acceptable.

In most applications you should explicitly convert data from untrusted sources, such as the client
request, to one of the types that cannot fail at runtime using a method like those listed under
**Non-panicking conversion**. This allows your application to handle conversion errors without
panicking, such as by falling back on a default value, removing invalid characters, or returning a
branded error page.
