# actix_web::actix::actix::dev::actors::mocker - Rust
API documentation for the Rust `mocker` mod in crate `actix_web`.
Keywords: rust, rustlang, rust-lang, mocker

# [−] Module actix_web::actix::actix::dev::actors::mocker

Mocking utility actor This actor wraps any actor, and replaces instances of that actor with mocker actor, which is able to accept all messages which the actor can receive.

Mocking is intended to be achieved by using a pattern similar to

ⓘThis example is not tested

    #[cfg(not(test))]
    type DBClientAct = DBClientActor;
    #[cfg(test)]
    type DBClientAct = Mocker<DBClientActor>;

Then, the actor should be used as a System Service (or Arbiter Service, but take care that all the places which will use the mocked actor is on the same arbiter). Thus, in a test, it will retrieve the mocker from the registry instead of the actual actor.

To set the mock function in the actor, the init_actor function is used, which allows the state of an actor to be set when it is started as a arbiter or system service. A closure which takes Box<Any> is evaluated for every message, and must return Box<Any>, specifically the return type for the message type send.

See the mock example to see how it can be used.

## Structs

Mocker | This actor is able to wrap another actor and accept all the messages the wrapped actor can, passing it to a closure which can mock the response of the actors

# Help

## Keyboard Shortcuts

`?`
  Show this help dialog
`S`
  Focus the search field
`↑`
  Move up in search results
`↓`
  Move down in search results
`↹`
  Switch tab
`⏎`
  Go to active search result
`+`
  Expand all sections
`-`
  Collapse all sections

## Search Tricks

Prefix searches with a type followed by a colon (e.g. `fn:`) to restrict the search to a given type.

Accepted types are: `fn`, `mod`, `struct`, `enum`, `trait`, `type`, `macro`, and `const`.

Search functions by type signature (e.g. `vec -> usize` or `* -> vec`)

Search multiple things at once by splitting your query with comma (e.g. `str,u8` or `String,struct:Vec,test`)