Skip to main content

ViewSet

Trait ViewSet 

Source
pub trait ViewSet: Send + Sync {
    // Required methods
    fn get_basename(&self) -> &str;
    fn dispatch<'life0, 'async_trait>(
        &'life0 self,
        request: Request,
        action: Action,
    ) -> Pin<Box<dyn Future<Output = Result<Response, Error>> + Send + 'async_trait>>
       where 'life0: 'async_trait,
             Self: 'async_trait;

    // Provided methods
    fn get_lookup_field(&self) -> &str { ... }
    fn get_extra_actions(&self) -> Vec<ActionMetadata> { ... }
    fn get_extra_action_url_map(&self) -> HashMap<String, String> { ... }
    fn get_current_base_url(&self) -> Option<String> { ... }
    fn reverse_action(
        &self,
        _action_name: &str,
        _args: &[&str],
    ) -> Result<String, Error> { ... }
    fn get_middleware(&self) -> Option<Arc<dyn ViewSetMiddleware>> { ... }
    fn requires_login(&self) -> bool { ... }
    fn get_required_permissions(&self) -> Vec<String> { ... }
}
Available on non-WebAssembly only.
Expand description

ViewSet trait - similar to Django REST Framework’s ViewSet Uses composition of mixins instead of inheritance

Required Methods§

Source

fn get_basename(&self) -> &str

Get the basename for URL routing

Source

fn dispatch<'life0, 'async_trait>( &'life0 self, request: Request, action: Action, ) -> Pin<Box<dyn Future<Output = Result<Response, Error>> + Send + 'async_trait>>
where 'life0: 'async_trait, Self: 'async_trait,

Dispatch request to appropriate action

Provided Methods§

Source

fn get_lookup_field(&self) -> &str

Get the lookup field for detail routes Defaults to “id” if not overridden

Source

fn get_extra_actions(&self) -> Vec<ActionMetadata>

Dispatch request with dependency injection context

Get extra actions defined on this ViewSet Returns custom actions decorated with #[action] or manually registered

Source

fn get_extra_action_url_map(&self) -> HashMap<String, String>

Get URL map for extra actions Returns empty map for uninitialized ViewSets

Source

fn get_current_base_url(&self) -> Option<String>

Get current base URL (only available after initialization)

Source

fn reverse_action( &self, _action_name: &str, _args: &[&str], ) -> Result<String, Error>

Reverse an action name to a URL

Source

fn get_middleware(&self) -> Option<Arc<dyn ViewSetMiddleware>>

Get middleware for this ViewSet Returns None if no middleware is configured

Source

fn requires_login(&self) -> bool

Check if login is required for this ViewSet

Source

fn get_required_permissions(&self) -> Vec<String>

Get required permissions for this ViewSet

Implementors§

Source§

impl ViewSet for SimpleViewSet

Source§

impl ViewSet for TestViewSet

Source§

impl<M, S> ViewSet for ModelViewSet<M, S>
where M: Send + Sync, S: Send + Sync,

Source§

impl<M, S> ViewSet for ReadOnlyModelViewSet<M, S>
where M: Send + Sync, S: Send + Sync,

Source§

impl<T> ViewSet for GenericViewSet<T>
where T: Send + Sync,