vulkan-int 0.5.4

empowering everyone to clamp integers in a memey way
Documentation
use
    std::
        {
            ops::
                {
                    RangeBounds,
                    Bound
                },
            
            cmp::
                PartialOrd
        };

pub
    fn clamp<
        N:
            PartialOrd +
            Copy,
        
        R: 
            RangeBounds<
                N
            >
    >(
        number:
            N,
        
        range:
            R
    ) ->
        N {
            match
                range
                    .contains(
                        &number
                    ) {
                        false =>
                            {
                                (
                                    match
                                        range
                                            .start_bound() {
                                                Bound::
                                                    Included(
                                                        &to
                                                    ) =>
                                                        match
                                                            number <= to {
                                                                false =>
                                                                    None,
                                                                
                                                                true =>
                                                                    Some(
                                                                        to
                                                                    )
                                                            },
                                                
                                                Bound::
                                                    Excluded(
                                                        &to
                                                    ) =>
                                                        match
                                                            number < to {
                                                                false =>
                                                                    None,
                                                                
                                                                true =>
                                                                    Some(
                                                                        to
                                                                    )
                                                            },
                                                
                                                Bound::
                                                    Unbounded =>
                                                        None
                                            }
                                )
                                    .or(
                                        match
                                            range
                                                .end_bound() {
                                                    Bound::
                                                        Included(
                                                            &to
                                                        ) =>
                                                            match
                                                                number >= to {
                                                                    false =>
                                                                        None,
                                                                    
                                                                    true =>
                                                                        Some(
                                                                            to
                                                                        )
                                                                },
                                                    
                                                    Bound::
                                                        Excluded(
                                                            &to
                                                        ) =>
                                                            match
                                                                number > to {
                                                                    false =>
                                                                        None,
                                                                    
                                                                    true =>
                                                                        Some(
                                                                            to
                                                                        )
                                                                },
                                                    
                                                    Bound::
                                                        Unbounded =>
                                                            None
                                                }
                                    )
                                    .unwrap()
                            },
                        
                        true =>
                            number
                    }
        }