Skip to content

Format nested mathces properly. #1454

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
May 1, 2017
Merged

Format nested mathces properly. #1454

merged 5 commits into from
May 1, 2017

Conversation

topecongiro
Copy link
Contributor

This PR closes #1371.

Input:

fn main() {
    Some(match type_ {
        sfEvtClosed => Closed,
        sfEvtResized => {
            let e = unsafe { *event.size.as_ref() };

            Resized {
                width: e.width,
                height: e.height,
            }
        }
        sfEvtLostFocus => LostFocus,
        sfEvtGainedFocus => GainedFocus,
        sfEvtTextEntered => {
            TextEntered {
                unicode: unsafe {
                    ::std::char::from_u32((*event.text.as_ref()).unicode)
                        .expect("Invalid unicode encountered on TextEntered event")
                },
            }
        }
        sfEvtKeyPressed => {
            let e = unsafe { event.key.as_ref() };

            KeyPressed {
                code: unsafe { ::std::mem::transmute(e.code) },
                alt: e.alt.to_bool(),
                ctrl: e.control.to_bool(),
                shift: e.shift.to_bool(),
                system: e.system.to_bool(),
            }
        }
        sfEvtKeyReleased => {
            let e = unsafe { event.key.as_ref() };

            KeyReleased {
                code: unsafe { ::std::mem::transmute(e.code) },
                alt: e.alt.to_bool(),
                ctrl: e.control.to_bool(),
                shift: e.shift.to_bool(),
                system: e.system.to_bool(),
            }
        }
    })
}

Output:

fn main() {
    Some(match type_ {
             sfEvtClosed => Closed,
             sfEvtResized => {
                 let e = unsafe { *event.size.as_ref() };

                 Resized {
                     width: e.width,
                     height: e.height,
                 }
             }
             sfEvtLostFocus => LostFocus,
             sfEvtGainedFocus => GainedFocus,
             sfEvtTextEntered => {
                 TextEntered {
                     unicode:
                         unsafe {
                             ::std::char::from_u32((*event.text.as_ref()).unicode)
                                 .expect("Invalid unicode encountered on TextEntered event")
                         },
                 }
             }
             sfEvtKeyPressed => {
                 let e = unsafe { event.key.as_ref() };

                 KeyPressed {
                     code: unsafe { ::std::mem::transmute(e.code) },
                     alt: e.alt.to_bool(),
                     ctrl: e.control.to_bool(),
                     shift: e.shift.to_bool(),
                     system: e.system.to_bool(),
                 }
             }
             sfEvtKeyReleased => {
                 let e = unsafe { event.key.as_ref() };

                 KeyReleased {
                     code: unsafe { ::std::mem::transmute(e.code) },
                     alt: e.alt.to_bool(),
                     ctrl: e.control.to_bool(),
                     shift: e.shift.to_bool(),
                     system: e.system.to_bool(),
                 }
             }
         })
}

@topecongiro
Copy link
Contributor Author

This PR closes #1395 and #1456 as well.

@nrc
Copy link
Member

nrc commented May 1, 2017

This looks great, thank you! Could you add some tests please?

@topecongiro
Copy link
Contributor Author

Hi, I added tests & rebased.

@nrc nrc merged commit c546f1b into rust-lang:master May 1, 2017
@nrc
Copy link
Member

nrc commented May 1, 2017

Thansk!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Weird formatting for nested match
2 participants